@tradecanvas/core 1.84.0 → 1.84.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./gpuContexts-BN9YuYEa.cjs`);let t=require(`@tradecanvas/commons`);function n(e){e.style.fontFeatureSettings=`normal`}var r=class{canvas;ctx;dpr=1;constructor(e,t){this.canvas=document.createElement(`canvas`),this.canvas.style.position=`absolute`,this.canvas.style.top=`0`,this.canvas.style.left=`0`,this.canvas.style.zIndex=String(t),this.canvas.style.pointerEvents=`none`,n(this.canvas),this.ctx=this.canvas.getContext(`2d`),e.appendChild(this.canvas)}resize(e,t){this.dpr=t;let n=Math.round(e.width*t),r=Math.round(e.height*t);(this.canvas.width!==n||this.canvas.height!==r)&&(this.canvas.width=n,this.canvas.height=r),this.canvas.style.width=`${e.width}px`,this.canvas.style.height=`${e.height}px`,this.ctx.setTransform(t,0,0,t,0,0)}clear(){this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(this.dpr,0,0,this.dpr,0,0)}getSize(){return{width:this.canvas.width/this.dpr,height:this.canvas.height/this.dpr}}destroy(){this.canvas.width=0,this.canvas.height=0,this.canvas.remove()}},i=class{scene=null;top=null;back=null;gpuCanvas=null;size=null;dpr=1;constructor(e){this.container=e}createLayers(){this.destroy(),this.scene=new r(this.container,0),this.top=new r(this.container,1)}getLayer(e){return(e===t.LayerType.Hover?this.top:this.scene)??void 0}backLayer(){return this.gpuCanvas?(this.back||(this.back=new r(this.container,0),this.container.insertBefore(this.back.canvas,this.gpuCanvas),this.size&&this.back.resize(this.size,this.dpr)),this.back):null}getDpr(){return this.dpr}dropBackLayer(){this.back?.destroy(),this.back=null}attachGpu(e){this.detachGpu(),e.style.position=`absolute`,e.style.top=`0`,e.style.left=`0`,e.style.zIndex=`0`,e.style.pointerEvents=`none`,this.container.insertBefore(e,this.scene?.canvas??null),this.gpuCanvas=e,this.size&&this.sizeGpu(this.size,this.dpr)}detachGpu(){this.dropBackLayer(),this.gpuCanvas&&(this.gpuCanvas.width=0,this.gpuCanvas.height=0,this.gpuCanvas.remove()),this.gpuCanvas=null}resize(e,t){this.size=e,this.dpr=t,this.scene?.resize(e,t),this.top?.resize(e,t),this.back?.resize(e,t),this.sizeGpu(e,t)}destroy(){this.detachGpu(),this.scene?.destroy(),this.top?.destroy(),this.scene=null,this.top=null}sizeGpu(e,t){let n=this.gpuCanvas;if(!n)return;let r=Math.round(e.width*t),i=Math.round(e.height*t);(n.width!==r||n.height!==i)&&(n.width=r,n.height=i),n.style.width=`${e.width}px`,n.style.height=`${e.height}px`}},a=class{animFrameId=0;running=!1;paused=!1;dirtyLayers=new Set;swapLayers=new Set;callback=null;setCallback(e){this.callback=e}markDirty(e){this.dirtyLayers.add(e),this.running&&!this.paused&&!this.animFrameId&&this.scheduleFrame()}markAllDirty(){this.dirtyLayers.add(t.LayerType.Background),this.dirtyLayers.add(t.LayerType.Main),this.dirtyLayers.add(t.LayerType.Overlay),this.dirtyLayers.add(t.LayerType.UI),this.dirtyLayers.add(t.LayerType.Hover),this.running&&!this.paused&&!this.animFrameId&&this.scheduleFrame()}start(){this.running=!0,this.markAllDirty()}pause(){this.paused=!0,this.animFrameId&&=(cancelAnimationFrame(this.animFrameId),0)}resume(){this.paused&&(this.paused=!1,this.running&&this.dirtyLayers.size>0&&!this.animFrameId&&this.scheduleFrame())}isPaused(){return this.paused}stop(){this.running=!1,this.animFrameId&&=(cancelAnimationFrame(this.animFrameId),0)}scheduleFrame(){this.animFrameId=requestAnimationFrame(()=>{if(this.animFrameId=0,!(!this.running||!this.callback)&&this.dirtyLayers.size>0){let e=this.dirtyLayers;this.dirtyLayers=this.swapLayers,this.callback(e),e.clear(),this.swapLayers=e}})}},o=2;function s(e=2){let t=typeof window<`u`&&window.devicePixelRatio||1;return e>0?Math.min(t,e):t}var c=class{observer=null;callback=null;currentDpr=1;resizeScheduled=!1;cachedSize;stopWatchingRatio=null;constructor(e,t=2){this.container=e,this.maxPixelRatio=t,this.currentDpr=s(t),this.cachedSize={width:e.clientWidth,height:e.clientHeight}}getDpr(){return this.currentDpr}getMaxPixelRatio(){return this.maxPixelRatio}setMaxPixelRatio(e){this.maxPixelRatio=e,this.update(!0)}getContainerSize(){return this.cachedSize}readContainerSize(){let e=this.container.clientWidth,t=this.container.clientHeight;return(e!==this.cachedSize.width||t!==this.cachedSize.height)&&(this.cachedSize={width:e,height:t}),this.cachedSize}onResize(e){this.callback=e,this.observer=new ResizeObserver(()=>{this.resizeScheduled||(this.resizeScheduled=!0,requestAnimationFrame(()=>{this.resizeScheduled=!1,this.update(!1)}))}),this.observer.observe(this.container),this.watchRatio()}update(e){let t=s(this.maxPixelRatio),n=this.container.clientWidth,r=this.container.clientHeight,i=t!==this.currentDpr||n!==this.cachedSize.width||r!==this.cachedSize.height;this.currentDpr=t,this.cachedSize={width:n,height:r},(i||e)&&this.callback?.(this.cachedSize,t)}watchRatio(){if(this.stopWatchingRatio?.(),this.stopWatchingRatio=null,typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(resolution: ${window.devicePixelRatio||1}dppx)`);if(!e||typeof e.addEventListener!=`function`)return;let t=()=>{this.update(!1),this.watchRatio()};e.addEventListener(`change`,t),this.stopWatchingRatio=()=>e.removeEventListener(`change`,t)}destroy(){this.observer?.disconnect(),this.observer=null,this.stopWatchingRatio?.(),this.stopWatchingRatio=null,this.callback=null}};function l(e,n,r,i){let a=n.scaleMode??(n.logScale?`logarithmic`:`regular`);return(a===`percentage`||a===`indexedTo100`)&&n.scaleBaseline?(0,t.formatPriceScaleLabel)(e,a,n.scaleBaseline,r,i):n.formatPrice?n.formatPrice(e):(0,t.formatPriceScaleLabel)(e,`regular`,void 0,r,i)}function u(e,t,n){return n!==null&&n>0?Math.max(1,Math.ceil(e/n-1e-9))*n:t===null?e:Math.max(e,10**-t)}var d=1e-9;function f(e,t){for(let n=0;n<t;n++){let t=10**n;if(e.every(e=>Math.abs(e*t-Math.round(e*t))<=d*Math.max(1,Math.abs(e*t))))return n}return t}function p(e,t,n){return Math.floor(t/n+1e-9)-Math.ceil(e/n-1e-9)+1}function m(e,t){if(!t||!(t>0)||e>=1)return e;let n=t;for(;n<e;)n*=2;return n}var h=24,g=200;function _(e){return Math.max(2,Math.min(h,Math.round(e/56)+1))}function v(e){if(!(e>0))return 0;let t=10**Math.floor(Math.log10(e)+1e-9),n=e/t;return(n<2?1:n<5?2:5)*t}function y(e){let t=10**Math.floor(Math.log10(e)+1e-9),n=e/t;return(n<1.5?2:n<3.5?5:10)*t}function b(e){return e<1?Math.ceil(-Math.log10(e))+1:+(e<10)}function x(e,n,r){let i=(0,t.computeTickStep)(e,n,_(r));if(!(i>0)||!(r>0))return i;let a=n-e;for(let e=0;e<8&&i/a*r<30;e++)i=y(i);return i}function S(e,t,n){if(!(n>0)||!(t>=e))return[];let r=[],i=Math.ceil(e/n-1e-9);if(!Number.isFinite(i)||Math.abs(i)>=2**53-1)return[];for(let e=i;e*n<=t+n*1e-9&&e-i<g;e++){let t=e*n;r.push(Math.abs(t)<n*1e-9?0:t)}return r}var C=12,w=14,T=class{locale=`en-US`;reservedPrice=null;precision=null;tick=null;rows=[];setPricePrecision(e){this.precision=e!==null&&Number.isInteger(e)&&e>=0?e:null}setPriceTick(e){this.tick=e!==null&&Number.isFinite(e)&&e>0?e:null}scale(e){let{min:n,max:r}=e.priceRange,i=x(n,r,e.chartRect.height),a=(0,t.autoPricePrecision)(n,r);if(e.priceUnit)return{step:m(i,e.priceUnit),precision:this.precision??a};let o=u(i,this.precision,this.tick);return p(n,r,o)<2?{step:i,precision:Math.max(this.precision??0,a)}:{step:o,precision:this.precision??a}}ticks(e){let{min:t,max:n}=e.priceRange;if(!(n-t>0))return[];let r=e.scaleMode??(e.logScale?`logarithmic`:`regular`),i=e.scaleBaseline;return(r===`percentage`||r===`indexedTo100`)&&i?this.rebasedTicks(e,r,i):r===`logarithmic`&&t>0?this.logTicks(e):S(t,n,this.scale(e).step)}rebasedTicks(e,t,n){let{min:r,max:i}=e.priceRange,a=t===`percentage`?100:0,o=e=>e/n*100-a,s=e=>(e+a)/100*n,c=Math.min(o(r),o(i)),l=Math.max(o(r),o(i));return S(c,l,x(c,l,e.chartRect.height)).map(s).sort((e,t)=>e-t)}logTicks(t){let{min:n,max:r}=t.priceRange,i=Math.log(r/n)/t.chartRect.height,a=e.E(t),o=Math.exp(-i*56),s=[],c=u(v(r*(1-o)),this.precision,this.tick),l=Math.floor(r/c+1e-9)*c,d=null;for(let e=0;e<200&&l>=n&&l>0;e++){let e=a(l);(d===null||Math.abs(e-d)>=30)&&(s.push(l),d=e);let t=l*o;if(c=u(v(Math.min(l-t,t)),this.precision,this.tick),!(c>0))break;let n=Math.round(t/c)*c;n>=l&&(n-=c),l=n}return s.length===0?S(n,r,this.scale(t).step):s.reverse()}labelText(e,t){return l(e,t,this.scale(t).precision,this.locale)}setReservedPriceProvider(e){this.reservedPrice=e}setLocale(e){this.locale=e}labelRows(){return this.rows}render(t,n,r,i=`right`,a=[]){let{chartRect:o,priceRange:s}=n,c=i===`left`,u=c?o.x:o.x+o.width;if(s.max-s.min<=0)return;let d=e.E(n);t.strokeStyle=r.style?.axis.price.line??r.axisLine,t.lineWidth=1,t.globalAlpha=.65,t.beginPath(),t.moveTo(u+.5,o.y),t.lineTo(u+.5,o.y+o.height),t.stroke(),t.globalAlpha=1;let{precision:p}=this.scale(n),m=this.ticks(n),h=n.scaleMode??(n.logScale?`logarithmic`:`regular`),g=h===`regular`||h===`logarithmic`?f(m,p):p,_=`500 ${r.font.sizeSmall}px ${r.font.family}`,v=[],y=c?null:this.reservedPrice?.()??null,b=y===null?null:e.T(y,n);for(let e of m){let t=d(e);b!==null&&Math.abs(t-b)<C||a.some(e=>Math.abs(t-e)<w)||v.push({y:t,text:l(e,n,g,this.locale)})}t.font=_,t.textBaseline=`middle`,t.textAlign=c?`right`:`left`,t.strokeStyle=r.style?.axis.price.line??r.axisLine,t.globalAlpha=.45,t.beginPath();let x=c?-1:1;for(let{y:e}of v)t.moveTo(u+x,e+.5),t.lineTo(u+4*x,e+.5);t.stroke(),t.globalAlpha=1,t.fillStyle=r.style?.axis.price.text??r.axisLabel;for(let{y:e,text:n}of v)t.fillText(n,u+8*x,e);c||(this.rows=v.map(e=>e.y))}};function E(e,t,n){let r=e.shape?.tagRadius;return typeof r==`number`&&Number.isFinite(r)?Math.max(0,Math.min(r,n/2,t/2)):0}function D(e,t,n,r,i,a){let o=E(a,r,i);if(e.beginPath(),!(o>0)){e.rect(t,n,r,i);return}e.moveTo(t+o,n),e.lineTo(t+r-o,n),e.arcTo(t+r,n,t+r,n+o,o),e.lineTo(t+r,n+i-o),e.arcTo(t+r,n+i,t+r-o,n+i,o),e.lineTo(t+o,n+i),e.arcTo(t,n+i,t,n+i-o,o),e.lineTo(t,n+o),e.arcTo(t,n,t+o,n,o),e.closePath()}function O(e,t,n,r,i,a){if(!(E(a,r,i)>0)){e.fillRect(t,n,r,i);return}D(e,t,n,r,i,a),e.fill()}function k(e){let t=Math.abs(e);return t>=1e3?1:t>=1?2:t>=.01?4:6}var A=16;function j(e,t,n,r=16){let i=r/2,a=e.map(e=>Math.min(Math.max(e,t+i),n-i));for(let e=1;e<a.length;e++)a[e]=Math.max(a[e],a[e-1]+r);a.length>0&&(a[a.length-1]=Math.min(a[a.length-1],n-i));for(let e=a.length-2;e>=0;e--)a[e]=Math.min(a[e],a[e+1]-r);if(a.length>0&&a[0]<t+i){a[0]=t+i;for(let e=1;e<a.length;e++)a[e]=Math.max(a[e],a[e-1]+r)}return a}function ee(e){let t=te(e);if(!t)return`#ffffff`;let[n,r,i]=t;return(.299*n+.587*r+.114*i)/255>.62?`#10131a`:`#ffffff`}function te(e){let t=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(t){let e=t[1].length===3?t[1].replace(/./g,e=>e+e):t[1];return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}let n=/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i.exec(e.trim());return n?[Number(n[1]),Number(n[2]),Number(n[3])]:null}function ne(e,t,n=[],r=16){let i=r/2,a=n.filter(e=>e.y+e.half>t.top&&e.y-e.half<t.bottom).sort((e,t)=>e.y-t.y),o=e.filter(e=>e.y>=t.top&&e.y<=t.bottom).sort((e,t)=>e.y-t.y),s=[],c=0,l=t.top;for(let e=0;e<=a.length;e++){e>0&&(l=Math.max(l,a[e-1].y+a[e-1].half));let n=l,u=e===a.length?t.bottom:a[e].y-a[e].half,d=e===a.length?1/0:a[e].y,f=c;for(;c<o.length&&o[c].y<d;)c++;let p=o.slice(f,c);if(p.length===0||u-n<r)continue;let m=j(p.map(e=>e.y),n,u,r);p.forEach((e,t)=>{m[t]-i>=n-.5&&m[t]+i<=u+.5&&s.push({...e,y:m[t]})})}return s}function re(e,t,n,r,i){if(t.length!==0){e.save(),e.font=`bold ${i.font.sizeSmall}px ${i.font.family}`,e.textBaseline=`middle`,e.textAlign=`left`;for(let a of t){let t=Math.min(e.measureText(a.text).width+10,r-2);e.fillStyle=a.color,O(e,n+1,Math.round(a.y-8),t,16,i),e.fillStyle=ee(a.color),e.fillText(a.text,n+5,Math.round(a.y))}e.restore()}}function ie(e,t,n,r,i,a){re(e,ne(t,i),n,r,a)}function ae(e){return{plot:e,plotText:null,panes:new Map}}function oe(e,t,n,r){let i=e.region(t),a=0;for(;a<n.length&&i.step(n[a]);)a++;let o=new Map;for(let t of r){let n=e.region(t.rect).step(t.background),r=e.region(t.inner),i=0;if(n)for(;i<t.steps.length&&r.step(t.steps[i]);)i++;o.set(t.id,{background:n,text:r,rest:t.steps.slice(i)})}return{plot:n.slice(a),plotText:i,panes:o}}var se=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange,s=r.barWidth,c=s+r.barSpacing,l=-r.offset+r.chartRect.x+s/2,{min:u,max:d}=r.priceRange;if(d-u===0)return;if(e.f(r)){e.p(t,n,r,i.candleUp,i.candleDown);return}let f=e.E(r);e.v(t,r=>{let{body:u,wick:d}=e.h(s,r.ratio),p=(u-d)/2,m=new Path2D,h=new Path2D,g=new Path2D,_=new Path2D;for(let e=a;e<=o&&e<n.length;e++){let t=n[e],i=t.close>=t.open,a=r.left(e*c+l,d),o=r.y(f(t.high)),s=r.y(f(t.low));(i?m:h).rect(a,Math.min(o,s),d,Math.max(Math.abs(s-o),1));let v=r.y(f(t.open)),y=r.y(f(t.close));(i?g:_).rect(a-p,Math.min(v,y),u,Math.max(Math.abs(y-v),d))}t.fillStyle=i.candleUpWick,t.fill(m),t.fillStyle=i.candleDownWick,t.fill(h),t.fillStyle=i.candleUp,t.fill(g),t.fillStyle=i.candleDown,t.fill(_)})}};function ce(e){if(e.style)return e.style.crosshair;let t=()=>({visible:!0,color:e.crosshair,style:`solid`,width:1});return{horizontal:t(),vertical:t(),labelBackground:e.text,labelText:e.background}}var le=16,ue=class{visible=!0;timeframeMs=0;setVisible(e){this.visible=e}isVisible(){return this.visible}setTimeframeMs(e){this.timeframeMs=e}isShown(e){return this.remaining(e)>0}render(e,t,n,r,i=null){let a=this.remaining(r);if(i===null||a<=0)return;let o=i.y+i.height;e.fillStyle=i.color,O(e,i.x,o,i.width,16,n),e.font=`${n.font.sizeSmall}px ${n.font.family}`,e.textBaseline=`middle`,e.textAlign=`left`,e.fillStyle=ee(i.color),e.fillText(this.formatRemaining(a),i.x+5,o+16/2)}remaining(e){if(!this.visible||!(this.timeframeMs>0)||e.length===0)return 0;let n=e[e.length-1].time*(0,t.barTimeUnit)(e)+this.timeframeMs-Date.now();return n>0?n:0}formatRemaining(e){let t=Math.ceil(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`:`${r}:${String(i).padStart(2,`0`)}`}};function de(e,t,n){let r=e.map(e=>e.y);if(e.length===0)return r;let i=t!==null&&e[t]?t:fe(e),a=e.map((e,t)=>t).filter(e=>e!==i),o=e[i].y,s=a.filter(t=>e[t].y<=o).sort((t,n)=>e[n].y-e[t].y),c=a.filter(t=>e[t].y>o).sort((t,n)=>e[t].y-e[n].y),l=r[i]-e[i].above;for(let t of s)r[t]+e[t].below>l&&(r[t]=l-e[t].below),l=r[t]-e[t].above;let u=r[i]+e[i].below;for(let t of c)r[t]-e[t].above<u&&(r[t]=u+e[t].above),u=r[t]+e[t].below;return n?r.map((t,r)=>t!==e[r].y&&(t-e[r].above<n.top||t+e[r].below>n.bottom)?NaN:t):r}function fe(e){let t=e.map(e=>e.y),n=(Math.min(...t)+Math.max(...t))/2,r=0;return t.forEach((e,i)=>{Math.abs(e-n)<Math.abs(t[r]-n)&&(r=i)}),r}var pe=20,me=8,he=14,ge=10,_e=8,ve=`#000`,ye=2,be=4.5;function xe(e,n){let r=n?.priceLimits??(n?.background&&Se(n.background)?t.LIGHT_PRICE_LIMITS:t.DARK_PRICE_LIMITS),i=e=>n?.background&&n.text?Te(e,n.background,n.text):e;return[{price:e.ceiling,color:i(e.colors?.ceiling??r.ceiling),label:`CE`},{price:e.floor,color:i(e.colors?.floor??r.floor),label:`FL`},{price:e.reference,color:i(e.colors?.reference??r.reference),label:`REF`}]}function Se(e){return(0,t.inkOn)(e,`#000000`,`#ffffff`)===`#000000`}var Ce=new Map,we=64;function Te(e,n,r){let i=`${e}|${n}|${r}`,a=Ce.get(i);return a===void 0&&(Ce.size>=we&&Ce.clear(),a=(0,t.readableOn)(e,n,r,be),Ce.set(i,a)),a}function Ee(e,t,n){if(!e)return null;let r=e.region(t,{text:!1});return n.every(e=>r.step(e))?e:null}var De=20,Oe=20,ke=class{layerManager;renderLoop;dprManager;renderCtx=null;sceneLayer;topLayer;gpu=null;lostGpu=null;onGpuLost=null;onGpuRestored=null;onContainerResize=null;constructor(e,t){this.layerManager=new i(e),this.renderLoop=new a,this.dprManager=new c(e,t),this.layerManager.createLayers(),this.cacheLayerRefs(),this.renderLoop.setCallback(e=>this.render(e)),this.dprManager.onResize((e,t)=>{this.layerManager.resize(e,t),this.renderLoop.markAllDirty(),this.onContainerResize?.(e)});let n=this.dprManager.getContainerSize(),r=this.dprManager.getDpr();this.layerManager.resize(n,r)}cacheLayerRefs(){this.sceneLayer=this.layerManager.getLayer(t.LayerType.Main),this.topLayer=this.layerManager.getLayer(t.LayerType.Hover)}setRenderContext(e){this.renderCtx=e}attachGpu(e){this.detachGpu(),this.placeGpu(e),e.onLost(()=>{this.gpu===e&&(this.gpu=null,this.lostGpu=e,this.layerManager.detachGpu(),this.renderLoop.markAllDirty(),this.onGpuLost?.())}),e.onRestored?.(()=>{this.lostGpu===e&&(this.lostGpu=null,this.placeGpu(e),this.onGpuRestored?.())})}placeGpu(e){this.gpu=e,this.layerManager.attachGpu(e.canvas),this.renderLoop.markAllDirty()}detachGpu(){let e=this.gpu??this.lostGpu;e&&(this.gpu=null,this.lostGpu=null,this.layerManager.detachGpu(),e.destroy(),this.renderLoop.markAllDirty())}renderNow(){this.render(new Set([t.LayerType.Main,t.LayerType.Hover]))}getGpu(){return this.gpu}start(){this.renderLoop.start()}stop(){this.renderLoop.stop()}requestRender(e){e===void 0?this.renderLoop.markAllDirty():this.renderLoop.markDirty(e)}render(e){let n=this.renderCtx;if(!n)return;let{chartRect:r}=n.viewport;if(r.width<=0||r.height<=0)return;let i=!1;for(let n of e)if(n!==t.LayerType.Hover){i=!0;break}i&&this.sceneLayer&&this.renderScene(this.sceneLayer,n),this.topLayer&&this.renderTop(this.topLayer,n)}renderScene(e,n){let{viewport:r,theme:i,data:a}=n;e.clear();let o=e.ctx,s=this.gpu,c=!!s&&n.chartRenderer instanceof se,l=n.chartRenderer?[e=>n.chartRenderer.render(e,a,r,i)]:[],u=[...c?[]:l,...n.compareRenderer?[e=>n.compareRenderer.render(e,a,r,i)]:[],...n.indicatorEngine?.overlayDraws(r,n.leftViewport??void 0)??[]],d=this.paneSteps(n),f={series:!1,volume:!1,background:!1},p=ae(u);s?({drawn:f,plan:p}=this.renderGpu(s,n,o,u,d),c&&!f.series&&(p={...p,plot:[...l,...p.plot]})):this.renderBackground(o,n),o.save(),o.beginPath(),o.rect(r.chartRect.x,r.chartRect.y,r.chartRect.width,r.chartRect.height),o.clip(),s||n.depthHeatmap?.render(o,r,i),f.volume||n.volumeRenderer?.render(o,a,r,i),s||(n.volumeProfile?.render(o,a,r,i),n.marketProfile?.render(o,a,r,i)),p.plotText?.drawText(o);for(let e of p.plot)e(o);n.periodLevels?.render(o,a,r,i),n.pivotMarkers?.render(o,a,r,i),n.renderOverlayPlugins?.(o,`main`),o.restore(),this.renderPanels(o,n,d,p);let m=this.axisTagPlan(n);n.priceLimits&&this.renderPriceLimits(o,r,i,n.priceLimits,n.formatPrice,m.limits),n.tradeZoneManager?.render(o,r,i),n.drawingRenderer?.render(o,r,i),n.priceLines?.render(o,r,i,a),n.currentPriceLine?.renderLine(o,r,i),n.tradingRenderer?.render(o,r,i),n.signalMarkerManager?.render(o,r,i),n.alertManager?.render(o,r,i);let h=m.fixed,g=n.indicatorValueLabels===!1?[]:this.overlayValueTags(n,h);n.priceAxis?.render(o,r,i,`right`,[...h.map(e=>e.y),...g.map(e=>e.y)]),re(o,g,r.chartRect.x+r.chartRect.width,r.priceAxisWidth??t.PRICE_AXIS_WIDTH,i),n.leftViewport&&(n.leftPriceAxis?.render(o,n.leftViewport,i,`left`),n.indicatorValueLabels!==!1&&this.renderLeftValueLabels(o,n,n.leftViewport)),n.tradingRenderer?.renderAxisBadges(o,r,i,m.trading),n.priceLines?.renderAxisTags(o,r,i,a,m.quote),n.currentPriceLine?.renderTag(o,r,i),n.timeAxis?.render(o,r,i,a,n.timeAxisY),this.renderPanelAxes(o,n),this.renderDrawingSpans(o,n)}renderDrawingSpans(e,t){if(t.crosshairHandler?.beginSpans?.(),!(t.drawingAxisSpans===!1||!t.drawingRenderer||!t.crosshairHandler))for(let n of t.drawingRenderer.axisSpans(t.viewport))t.crosshairHandler.renderSpan(e,n,t.viewport,t.theme,t.data,t.timeAxisY)}renderGpu(t,n,r,i,a){let{viewport:o,theme:s,data:c}=n,l=this.layerManager.getDpr(),u=this.underSteps(n),d=!!(n.marketProfile?.isVisible()&&n.marketProfile.drawsText()),f=u.length>0&&!d?Ee(t.recorder?.(l,r)??null,o.chartRect,u):null,p=u.length>0&&!f,m=t.recorder?.(l,r)??null,h=m?oe(m,o.chartRect,i,a):ae(i),g=!!(n.volumeProfile?.isVisible()||n.marketProfile?.isVisible()),_=!!n.gridRenderer?.isVisible()&&!e.s(s),v=n.watermark?.isVisible()||p||_?null:{grid:n.gridRenderer?.isVisible()??!1,marks:n.gridRenderer?.isVisible()?Ae(n):void 0,rects:[...n.sessionShading?.rects(c,o,s)??[],...n.sessionBreaks?.lineRects(o,s,c)??[]]},y=n.volumeRenderer?.isVisible()&&!g?{heightRatio:n.volumeRenderer.getHeightRatio()}:null,b=t.render({data:c,viewport:o,theme:s,dpr:l,candles:n.chartRenderer instanceof se,volume:y,background:v,under:f,recorded:m,seriesRevision:n.seriesRevision}),x=b.recorded?h:ae(i),S={drawn:{...b,volume:b.volume||g},plan:x},C=v!==null&&!!b.background,w=f!==null&&b.under?[]:u;return C&&w.length===0?(this.layerManager.dropBackLayer(),S):(this.renderBackCanvas(n,w,!C),S)}underSteps(e){let{viewport:t,theme:n,data:r}=e,i=[];return e.depthHeatmap?.isVisible()&&i.push(r=>e.depthHeatmap.render(r,t,n)),(e.volumeProfile?.isVisible()||e.marketProfile?.isVisible())&&(e.volumeRenderer?.isVisible()&&i.push(i=>e.volumeRenderer.render(i,r,t,n)),e.volumeProfile?.isVisible()&&i.push(i=>e.volumeProfile.render(i,r,t,n)),e.marketProfile?.isVisible()&&i.push(i=>e.marketProfile.render(i,r,t,n))),i}renderBackCanvas(e,t,n){let r=this.layerManager.backLayer();r&&(r.clear(),n&&this.renderBackground(r.ctx,e),t.length>0&&this.inPlot(r.ctx,e.viewport,()=>t.forEach(e=>e(r.ctx))))}renderBackground(e,t){let{viewport:n,theme:r,data:i}=t;t.gridRenderer?.isVisible()&&t.gridRenderer.render(e,n,r,Ae(t)),t.sessionShading?.render(e,i,n,r),t.sessionBreaks?.renderLines(e,n,r,i),t.watermark?.render(e,n,r)}inPlot(e,t,n){e.save(),e.beginPath(),e.rect(t.chartRect.x,t.chartRect.y,t.chartRect.width,t.chartRect.height),e.clip(),n(),e.restore()}renderTop(e,t){let{viewport:n,theme:r,data:i}=t;e.clear();let a=e.ctx;t.drawingRenderer?.renderHover(a,n,r),t.measureOverlay?.render(a,n,r),t.selectionBoxOverlay?.render(a,n,r),t.crosshairHandler?.render(a,n,r),t.renderOverlayPlugins?.(a,`overlay`),this.renderPanelCrosshair(a,t),t.barCountdown?.render(a,n,r,i,t.currentPriceLine?.getTag()??null),t.crosshairHandler?.renderAxisLabels(a,n,r,i,t.timeAxisY,t.priceAxis?.labelRows(),t.timeAxis?.labelColumns()),t.priceAxisAddButton?.render(a,n,r,t.crosshairHandler?.getPosition()??null),this.renderLegend(a,t),t.renderOverlayPlugins?.(a,`ui`),this.renderPanelHoverValues(a,t)}renderLegend(e,t){if(!t.chartLegend)return;let{viewport:n,theme:r,data:i}=t,a=t.tradingRenderer?.tagRects()??[];if(a.length===0){t.chartLegend.render(e,n,r,i);return}let{x:o,y:s,width:c,height:l}=n.chartRect;e.save();try{for(let t of a)e.beginPath(),e.rect(o,s,c,l),e.rect(t.x,t.y,t.width,t.height),e.clip(`evenodd`);t.chartLegend.render(e,n,r,i)}finally{e.restore()}}paneSteps(e){let{theme:t,panels:n}=e,r=e.indicatorEngine;if(!r||n.length===0)return[];let i=[];for(let e of n){let{rect:n,viewport:a}=e;if(n.width<=0||n.height<=0)continue;let o=e.members?.length?[e.instanceId,...e.members]:[e.instanceId],s=[];for(let e of o){let n=r.isShown(e)?r.getLevels(e):[];n.length>0&&s.push(e=>this.renderLevels(e,n,a,t))}for(let e of o)s.push(t=>r.renderPanel(t,e,a));i.push({id:e.instanceId,rect:n,inner:{x:n.x,y:n.y+pe,width:n.width,height:n.height-pe},background:r=>{r.fillStyle=e.style?.background??t.style?.panes.background??t.background,r.fillRect(n.x,n.y,n.width,n.height)},steps:s})}return i}renderPanels(e,t,n,r){let{theme:i}=t,a=t.indicatorEngine;if(!a||n.length===0)return;let o=`10px ${i.font.family}`,s=this.panelDescriptors(a),c=new Map(t.panels.map(e=>[e.instanceId,e.style]));for(let a of n){let{rect:n,inner:l}=a,u=r.panes.get(a.id),d=c.get(a.id);e.save(),e.beginPath(),e.rect(n.x,n.y,n.width,n.height),e.clip(),u?.background||a.background(e),e.fillStyle=d?.separator??i.style?.panes.separator??i.axisLine,e.fillRect(n.x,n.y,n.width,3),e.fillStyle=i.style?.panes.title??i.textSecondary,e.font=o,e.textBaseline=`top`,e.textAlign=`left`;let f=s.get(a.id);f&&t.paneTitles!==!1&&e.fillText(f.descriptor.name,n.x+6,n.y+6),e.save(),e.beginPath(),e.rect(l.x,l.y,l.width,l.height),e.clip(),u?.text?.drawText(e);for(let t of u?u.rest:a.steps)t(e);e.restore(),e.restore()}}axisTagPlan(t){let{viewport:n,data:r}=t,{chartRect:i}=n,a=e=>e>=i.y&&e<=i.y+i.height,o=[],s=t.currentPriceLine?.isVisible()&&t.theme.style?.lastPrice.visible!==!1?t.currentPriceLine.getPrice():null;if(s!=null&&a(e.T(s,n))){let i=t.barCountdown?.isShown(r)?16:0;o.push({y:e.T(s,n),above:ge,below:ge+i,source:`last`,key:0})}for(let i of t.priceLines?.levels(r,n)??[]){let t=e.T(i.price,n);a(t)&&o.push({y:t,above:_e,below:_e,source:`quote`,key:i.kind})}(t.priceLimits?xe(t.priceLimits):[]).forEach(({price:t},r)=>{let i=e.T(t,n);a(i)&&o.push({y:i,above:he/2,below:he/2,source:`limit`,key:r})});let c=t.alignAxisLabels!==!1;c&&(t.tradingRenderer?.axisBadgeLines(n,t.theme)??[]).forEach((e,t)=>{o.push({y:e,above:16/2,below:16/2,source:`trading`,key:t})});let l=o.findIndex(e=>e.source===`last`),u={top:i.y,bottom:i.y+i.height},d=c?de(o,l>=0?l:null,u):o.map(e=>e.y),f={fixed:[],quote:new Map,limits:[],trading:c?[]:void 0};if(o.forEach((e,t)=>{Number.isNaN(d[t])||f.fixed.push({y:d[t]+(e.below-e.above)/2,half:(e.above+e.below)/2}),e.source===`quote`?f.quote.set(e.key,d[t]):e.source===`limit`?f.limits[e.key]=d[t]:e.source===`trading`&&(f.trading[e.key]=d[t])}),!c)for(let e of t.tradingRenderer?.axisTagYs(n,t.theme)??[])a(e)&&f.fixed.push({y:e,half:16/2});return f}overlayValueTags(n,r){let i=n.indicatorEngine?.getLatestOverlayValues();if(!i?.length)return[];let{viewport:a}=n,{chartRect:o}=a,s=n.numberLocale??`en-US`,c=(a.scaleMode===`percentage`||a.scaleMode===`indexedTo100`)&&a.scaleBaseline?e=>l(e,a,2,s):n.formatPrice??(e=>(0,t.formatPrice)(e,2,s));return ne(i.map(t=>({y:e.T(t.value,a),text:c(t.value),color:t.color})),{top:o.y,bottom:o.y+o.height},r)}renderLeftValueLabels(n,r,i){let a=r.indicatorEngine?.getLatestOverlayValues(`left`);if(!a?.length)return;let{chartRect:o}=i,s=r.leftAxisWidth??t.PRICE_AXIS_WIDTH,c=(0,t.autoPricePrecision)(i.priceRange.min,i.priceRange.max),l=r.numberLocale??`en-US`;ie(n,a.map(n=>({y:e.T(n.value,i),text:(0,t.formatPrice)(n.value,c,l),color:n.color})),o.x-s,s,{top:o.y,bottom:o.y+o.height},r.theme)}renderLevels(t,n,r,i){if(n.length===0)return;let{chartRect:a}=r;t.save(),t.strokeStyle=i.axisLabel,t.globalAlpha=.45,t.lineWidth=1,t.setLineDash([4,4]),t.beginPath();for(let i of n){let n=Math.round(e.T(i,r))+.5;t.moveTo(a.x,n),t.lineTo(a.x+a.width,n)}t.stroke(),t.restore()}renderPanelAxes(n,r){let{theme:i}=r,a=r.numberLocale??`en-US`,o=`${i.font.sizeSmall}px ${i.font.family}`;for(let s of r.panels){let c=s.viewport,u=s.rect,{min:d,max:f}=c.priceRange;if(f-d<=0||u.height<=0||c.chartRect.height<me)continue;let p=u.x+u.width,m=c.chartRect,h=i.style?.axis.price.line??i.axisLine,g=i.style?.axis.price.text??i.axisLabel;n.strokeStyle=h,n.lineWidth=1,n.beginPath(),n.moveTo(p+.5,u.y),n.lineTo(p+.5,u.y+u.height),n.stroke();let _=x(d,f,m.height),v=b(_);n.font=o,n.textBaseline=`middle`,n.textAlign=`left`;for(let t of S(d,f,_)){let r=e.T(t,c);r<m.y||r>m.y+m.height||(n.strokeStyle=h,n.beginPath(),n.moveTo(p,Math.round(r)+.5),n.lineTo(p+4,Math.round(r)+.5),n.stroke(),n.fillStyle=g,n.fillText(l(t,c,v,a),p+6,r))}let y=r.indicatorValueLabels===!1?null:[s.instanceId,...s.members??[]].flatMap(e=>r.indicatorEngine?.getLatestValues(e)??[]);y?.length&&ie(n,y.map(n=>({y:e.T(n.value,c),text:c.scaleMode===`percentage`&&c.scaleBaseline?l(n.value,c,2,a):(0,t.formatPrice)(n.value,k(n.value),a),color:n.color})),p,r.viewport.priceAxisWidth??t.PRICE_AXIS_WIDTH,{top:m.y,bottom:m.y+m.height},i)}}renderPanelCrosshair(n,r){let i=r.crosshairHandler?.getPosition();if(!i||r.panels.length===0||!r.crosshairHandler?.drawsLines())return;let{theme:a}=r;for(let o of r.panels){let s=o.rect;if(i.x<s.x||i.x>s.x+s.width||i.y<s.y||i.y>s.y+s.height)continue;let c=o.viewport;if(c.chartRect.height<me)continue;let l=e.A(i.x,c),u=e.b(Math.max(0,Math.min((r.data?.length??1)-1,Math.round(l))),c),d=ce(a);if(n.save(),n.beginPath(),n.rect(s.x,s.y,s.width,s.height),n.clip(),d.vertical.visible){n.setLineDash((0,t.lineDash)(d.vertical.style,[4,4],d.vertical.width)),n.strokeStyle=d.vertical.color;let r=e.g(n,u,d.vertical.width);n.lineWidth=r.width,n.beginPath(),n.moveTo(r.x,s.y),n.lineTo(r.x,s.y+s.height),n.stroke()}if(d.horizontal.visible){n.setLineDash((0,t.lineDash)(d.horizontal.style,[4,4],d.horizontal.width)),n.strokeStyle=d.horizontal.color;let r=e._(n,i.y,d.horizontal.width);n.lineWidth=r.width,n.beginPath(),n.moveTo(s.x,r.y),n.lineTo(s.x+s.width,r.y),n.stroke()}n.setLineDash([]),n.restore();break}}renderPanelHoverValues(n,r){let i=r.crosshairHandler?.getPosition(),a=r.indicatorEngine;if(!i||r.panels.length===0)return;let{theme:o,viewport:s,data:c}=r,u=r.numberLocale??`en-US`,d=`${o.font.sizeSmall}px ${o.font.family}`,f=a?this.panelDescriptors(a):null;for(let p of r.panels){let m=p.viewport,h=p.rect,{min:g,max:_}=m.priceRange;if(_-g<=0||h.height<=0||m.chartRect.height<me)continue;let v=h.x+h.width,y=b(x(g,_,m.chartRect.height));if(r.crosshairHandler?.getMode()!==`hidden`&&i.x>=h.x&&i.x<=h.x+h.width&&i.y>=h.y&&i.y<=h.y+h.height){let r=l(e.M(i.y,m),m,y,u);n.font=`bold ${o.font.sizeSmall}px ${o.font.family}`;let a=n.measureText(r).width,c=Math.min(a+De,(s.priceAxisWidth??t.PRICE_AXIS_WIDTH)-2),d=ce(o);n.fillStyle=d.labelBackground,O(n,v+1,i.y-Oe/2,c,Oe,o),n.fillStyle=d.labelText,n.textBaseline=`middle`,n.textAlign=`left`,n.fillText(r,v+5,i.y)}if(!a||r.paneTitles===!1||!a.isShown(p.instanceId))continue;let S=Math.max(0,Math.min((c?.length??1)-1,Math.round(e.A(i.x,m)))),C=a.peekOutput(p.instanceId),w=C?.series&&S<C.series.length?C.series[S]:null;if(!w)continue;let T=f?.get(p.instanceId),E=T?.descriptor.plots,D=[];if(E)for(let e of E){let t=w[e.key];t!==void 0&&Number.isFinite(t)&&D.push(`${e.title} ${l(t,m,y,u)}`)}else for(let e in w){let t=w[e];t!==void 0&&D.push(`${e}: ${t.toFixed(y)}`)}if(D.length===0)continue;n.font=d;let k=T?n.measureText(T.descriptor.name).width+14:10;n.fillStyle=o.textSecondary,n.textBaseline=`top`,n.textAlign=`left`,n.fillText(D.join(` `),h.x+k,h.y+6)}}panelDescriptors(e){let t=new Map;for(let n of e.getPanelIndicators())t.set(n.instanceId,n);return t}renderPriceLimits(n,r,i,a,o,s=[]){let{chartRect:c}=r,l=o??(e=>(0,t.priceTagText)(e,r,r.pricePrecision??ye)),u=`bold 9px ${i.font.family}`,d=`10px ${i.font.family}`;xe(a,i).forEach(({price:a,color:o,label:f},p)=>{let m=e.T(a,r);if(m<c.y||m>c.y+c.height)return;n.setLineDash([8,4]),n.strokeStyle=o,n.lineWidth=1,n.beginPath(),n.moveTo(c.x,Math.round(m)+.5),n.lineTo(c.x+c.width,Math.round(m)+.5),n.stroke(),n.setLineDash([]),n.font=u,n.fillStyle=o,n.textBaseline=`bottom`,n.textAlign=`left`,n.fillText(`${f} ${l(a)}`,c.x+4,m-2);let h=s[p]??m;if(Number.isNaN(h))return;let g=c.x+c.width+1;n.fillStyle=o,O(n,g,h-he/2,(r.priceAxisWidth??t.PRICE_AXIS_WIDTH)-2,he,i),n.fillStyle=i.background&&i.text?(0,t.inkOn)(o,i.background,i.text):ve,n.font=d,n.textBaseline=`middle`,n.textAlign=`left`,n.fillText(l(a),g+4,h)})}destroy(){this.renderLoop.stop(),this.detachGpu(),this.dprManager.destroy(),this.layerManager.destroy()}};function Ae(e){return{prices:e.priceAxis?.ticks(e.viewport),slots:e.timeAxis?.marks(e.viewport,e.data).map(e=>e.index)}}async function je(t){let n=e.n();if(!n)return{gpu:null,reason:`limit`};let r;try{r=await Promise.resolve().then(()=>require(`./WebGLSeriesRenderer-lwJz1WAg.cjs`))}catch(e){return n(),console.warn(`TradeCanvas: the WebGL renderer failed to load, drawing with Canvas 2D.`,e),{gpu:null,reason:`unsupported`}}let i=r.WebGLSeriesRenderer.create({failIfMajorPerformanceCaveat:t===`auto`,release:n});return i?{gpu:i}:(n(),{gpu:null,reason:`unsupported`})}async function Me(e){return(await je(e)).gpu}var Ne=.25,Pe=.02,Fe=1/t.PHI,Ie=t.PHI**4,Le=t.PHI**-5,Re=.2,ze=class{state;priceAxisWidth=t.PRICE_AXIS_WIDTH;stateCache=null;dataLength=0;margins={top:Le,bottom:Le};minBarWidth;maxBarWidth;rightMarginBars;freePan=!0;minVisibleBars=3;minBarUnit=Ne;barLayout=`classic`;constructor(e,n,r=2,i=30,a=5){this.minBarWidth=r,this.maxBarWidth=i,this.rightMarginBars=a;let o=this.computeChartRect(e,n);this.state={visibleRange:{from:0,to:0},priceRange:{min:0,max:1},barWidth:t.DEFAULT_BAR_WIDTH,barSpacing:t.DEFAULT_BAR_SPACING,offset:0,chartRect:o}}getState(){return this.stateCache||={visibleRange:{...this.state.visibleRange},priceRange:{...this.state.priceRange},barWidth:this.state.barWidth,barSpacing:this.state.barSpacing,offset:this.state.offset,chartRect:{...this.state.chartRect},logScale:this.state.logScale,scaleMode:this.state.scaleMode,scaleBaseline:this.state.scaleBaseline,invertScale:this.state.invertScale,priceAxisWidth:this.state.priceAxisWidth,formatPrice:this.state.formatPrice,numberLocale:this.state.numberLocale,pricePrecision:this.state.pricePrecision,priceUnit:this.state.priceUnit},this.stateCache}invalidate(){this.stateCache=null}setLogScale(e){this.setScaleMode(e?`logarithmic`:`regular`)}isLogScale(){return(this.state.scaleMode??(this.state.logScale?`logarithmic`:`regular`))===`logarithmic`}setScaleMode(e){this.state.scaleMode=e,this.state.logScale=e===`logarithmic`,this.invalidate()}getScaleMode(){return this.state.scaleMode??(this.state.logScale?`logarithmic`:`regular`)}setInvertScale(e){this.state.invertScale=e,this.invalidate()}isInvertScale(){return this.state.invertScale===!0}setNumberLocale(e){this.state.numberLocale=e,this.invalidate()}setPricePrecision(e){this.state.pricePrecision=e!==null&&Number.isInteger(e)&&e>=0?e:void 0,this.invalidate()}setPriceFormat(e,t=null){this.state.formatPrice=e??void 0,this.state.priceUnit=t??void 0,this.invalidate()}setScaleBaseline(e){this.state.scaleBaseline=e,this.invalidate()}setRightMargin(e){this.rightMarginBars=e}getRightMargin(){return this.rightMarginBars}setPanLimits(e){e.freePan!==void 0&&(this.freePan=e.freePan),e.minVisibleBars!==void 0&&(this.minVisibleBars=Math.max(1,Math.floor(e.minVisibleBars))),this.clampOffset(),this.updateVisibleRange()}endOffset(){let e=this.state.barWidth+this.state.barSpacing;return this.dataLength*e-this.state.chartRect.width+this.rightMarginBars*e}setPriceAxisWidth(e){this.priceAxisWidth!==e&&(this.priceAxisWidth=e,this.state.priceAxisWidth=e,this.invalidate())}computeChartRect(e,n){return{x:0,y:0,width:Math.max(0,e-this.priceAxisWidth),height:Math.max(0,n-t.TIME_AXIS_HEIGHT)}}resize(e,t){this.state.chartRect=this.computeChartRect(e,t),this.invalidate(),this.clampUnit(),this.clampOffset()}setChartRect(e){this.state.chartRect={x:e.x,y:e.y,width:Math.max(0,e.width),height:Math.max(0,e.height)},this.invalidate(),this.clampUnit(),this.clampOffset(),this.updateVisibleRange()}setBarLayout(e){let t=e===`golden`?`golden`:`classic`;if(t===this.barLayout)return;let n=this.dataLength>0&&this.isAtEnd();this.barLayout=t,this.applyUnit(this.dataLength===0?this.openingUnit():this.state.barWidth+this.state.barSpacing),this.clampUnit(),n&&(this.state.offset=this.endOffset(),this.invalidate()),this.clampOffset(),this.updateVisibleRange()}getBarLayout(){return this.barLayout}openingUnit(){return this.barLayout===`golden`?Ie:t.DEFAULT_BAR_WIDTH+t.DEFAULT_BAR_SPACING}floorUnit(){return this.barLayout===`golden`?this.minBarWidth/Fe:this.minBarWidth+t.DEFAULT_BAR_SPACING}minUnit(){let e=this.floorUnit(),t=this.state.chartRect.width,n=this.dataLength+this.rightMarginBars;return t<=0||n<=0?e:Math.max(this.minBarUnit,Math.min(e,t/n))}setMinBarUnit(e){this.minBarUnit=Number.isFinite(e)?Math.max(Pe,Math.min(e,this.floorUnit())):Ne,this.clampUnit(),this.clampOffset(),this.updateVisibleRange(),this.invalidate()}getMinBarUnit(){return this.minBarUnit}maxUnit(){return this.barLayout===`golden`?this.maxBarWidth/Fe:this.maxBarWidth+t.DEFAULT_BAR_SPACING}applyUnit(e){let n=this.floorUnit();if(this.barLayout===`golden`)this.state.barWidth=e*Fe,this.state.barSpacing=e-this.state.barWidth;else if(e>=n)this.state.barWidth=e-t.DEFAULT_BAR_SPACING,this.state.barSpacing=t.DEFAULT_BAR_SPACING;else{let t=this.minBarWidth/n;this.state.barWidth=e*t,this.state.barSpacing=e-this.state.barWidth}this.invalidate()}clampUnit(){let e=this.state.barWidth+this.state.barSpacing,n=(0,t.clamp)(e,this.minUnit(),this.maxUnit());n===e||e<=0||(this.state.offset=this.state.offset/e*n,this.applyUnit(n))}updateData(e,n){let r=this.dataLength===0;if(this.dataLength=e.length,this.dataLength!==0&&(this.clampUnit(),r&&(this.state.offset=this.endOffset()),this.clampOffset(),this.updateVisibleRange(),n)){let{min:n,max:r}=(0,t.computePriceRange)(e,this.state.visibleRange.from,Math.min(this.state.visibleRange.to,this.dataLength-1),0);this.fitToPrices(n,r)}}setScaleMargins(e){let t=e=>Number.isFinite(e)&&e>=0;!t(e.top)||!t(e.bottom)||1-e.top-e.bottom<Re||(this.margins={top:e.top,bottom:e.bottom})}getScaleMargins(){return{...this.margins}}fitToPrices(e,n){this.state.priceRange=(0,t.fitPriceRange)(e,n,this.margins,this.isLogScale()),this.invalidate()}prependBars(e){e===0||!Number.isFinite(e)||(this.dataLength+=e,this.state.offset+=e*(this.state.barWidth+this.state.barSpacing),this.invalidate(),this.updateVisibleRange())}setPriceRange(e,t){this.state.priceRange={min:e,max:t},this.invalidate()}scalePriceRange(e){if(!Number.isFinite(e)||e<=0)return;let{min:t,max:n}=this.state.priceRange,r=(t+n)/2,i=(n-t)/2,a=Math.max(i*e,1e-9);this.state.priceRange={min:r-a,max:r+a},this.invalidate()}scrollBy(e){this.state.offset+=e,this.invalidate(),this.clampOffset(),this.updateVisibleRange()}panPriceRange(e){let t=this.state.chartRect.height;if(t<=0||e===0)return;let{min:n,max:r}=this.state.priceRange,i=(this.state.invertScale?-e:e)/t;if(this.isLogScale()&&n>0&&r>0){let e=Math.log(n),t=Math.log(r),a=(t-e)*i;this.state.priceRange={min:Math.exp(e-a),max:Math.exp(t-a)},this.invalidate();return}let a=(r-n)*i;this.state.priceRange={min:n-a,max:r-a},this.invalidate()}isAtEnd(){let e=this.state.barWidth+this.state.barSpacing;return Math.abs(this.state.offset-this.endOffset())<=e*2}scrollToEnd(){this.state.offset=this.endOffset(),this.invalidate(),this.updateVisibleRange()}zoom(e,n){let r=this.state.barWidth+this.state.barSpacing,i=this.state.barWidth*(1+e),a=(0,t.clamp)(this.barLayout===`classic`&&r>=this.floorUnit()&&i>=this.minBarWidth?i+t.DEFAULT_BAR_SPACING:r*(1+e),this.minUnit(),this.maxUnit());if(a===r)return;let o=this.isAtEnd(),s=(this.state.offset+n)/r;this.applyUnit(a),this.state.offset=o?this.endOffset():s*a-n,this.invalidate(),this.clampOffset(),this.updateVisibleRange()}zoomToBarRange(e,n){let r=this.state.chartRect.width;if(r<=0||!Number.isFinite(e)||!Number.isFinite(n)||n<e)return;let i=(0,t.clamp)(r/(n-e+1),this.minUnit(),this.maxUnit());this.applyUnit(i),this.state.offset=(e+n+1)/2*i-r/2,this.invalidate(),this.clampOffset(),this.updateVisibleRange()}clampOffset(){if(this.state.chartRect.width<=0)return;let e=this.state.barWidth+this.state.barSpacing,n=this.state.chartRect.width,r=this.endOffset(),i,a;if(this.freePan&&this.dataLength>0){let t=Math.min(this.minVisibleBars,this.dataLength);i=t*e-n,a=(this.dataLength-t)*e,i=Math.min(i,r),a=Math.max(a,r)}else if(r>0)i=-(n*.5),a=r;else{let e=n*.5;i=r-e,a=r+e}this.state.offset=(0,t.clamp)(this.state.offset,i,a),this.invalidate()}updateVisibleRange(){let e=this.state.barWidth+this.state.barSpacing;if(e<=0||this.state.chartRect.width<=0)return;let t=Math.floor(this.state.offset/e),n=Math.ceil(this.state.chartRect.width/e)+1,r=Math.min(t+n,this.dataLength-1);this.state.visibleRange={from:Math.max(0,t),to:Math.max(0,r)},this.invalidate()}};function Be(e,n){return(0,t.sliceVisibleData)(e,n.visibleRange.from,n.visibleRange.to)}var Ve=[`1D`,`5D`,`1M`,`3M`,`6M`,`YTD`,`1Y`,`5Y`,`All`],He=864e5,Ue=6e4,We={"1M":1,"3M":3,"6M":6,"1Y":12,"5Y":60};function Ge(e,t){let n=new Date(e),r=n.getUTCFullYear(),i=n.getUTCMonth()+t,a=new Date(Date.UTC(r,i+1,0)).getUTCDate();return Date.UTC(r,i,Math.min(n.getUTCDate(),a),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds())}function Ke(e,n,r=0){if(e===`All`)return null;if(e===`1D`)return n-He;if(e===`5D`)return n-5*He;let i=n+(0,t.offsetAt)(r,n)*Ue;return e===`YTD`?(0,t.wallToUtc)(Date.UTC(new Date(i).getUTCFullYear(),0,1),r):(0,t.wallToUtc)(Ge(i,-(We[e]??0)),r)}function qe(e,t,n){if(t>=e){let t=Array(Math.max(0,e));for(let n=0;n<e;n++)t[n]=n;return t}if(t<=2)return e>=2?[0,e-1]:e===1?[0]:[];let r=[0],i=(e-2)/(t-2),a=0;for(let o=0;o<t-2;o++){let t=Math.floor((o+1)*i)+1,s=Math.floor((o+2)*i)+1;s>e&&(s=e);let c=0,l=0,u=0;for(let e=t;e<s;e++)c+=e,l+=n(e),u++;if(u>0)c/=u,l/=u;else{let r=Math.min(t,e-1);c=r,l=n(r)}let d=Math.floor(o*i)+1,f=Math.floor((o+1)*i)+1,p=n(a),m=-1,h=d;for(let e=d;e<f;e++){let t=Math.abs((a-c)*(n(e)-p)-(a-e)*(l-p));t>m&&(m=t,h=e)}r.push(h),a=h}return r.push(e-1),r}var Je=64;function Ye(e,t,n,r,i){let a=Math.max(0,e),o=Math.min(t,n-1);if(o<a)return[];let s=o-a+1,c=Math.max(Je,Math.ceil(r*2));if(s<=c){let e=Array(s);for(let t=0;t<s;t++)e[t]=a+t;return e}let l=qe(s,c,e=>i(a+e));for(let e=0;e<l.length;e++)l[e]+=a;return l}var Xe=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange;if(a>o||n.length===0)return;let s=r.barWidth+r.barSpacing,c=-r.offset+r.chartRect.x+r.barWidth/2,{min:l,max:u}=r.priceRange;if(u-l===0)return;let d=e.E(r);t.beginPath(),t.strokeStyle=i.lineColor,t.lineWidth=i.style?.series.lineWidth??2,t.lineJoin=`round`;let f=Ye(a,o,n.length,r.chartRect.width,e=>n[e].close),p=!1;for(let e of f){let r=e*s+c,i=d(n[e].close);p?t.lineTo(r,i):(t.moveTo(r,i),p=!0)}t.stroke()}},Ze=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange;if(a>o||n.length===0)return;let s=r.barWidth+r.barSpacing,c=-r.offset+r.chartRect.x+r.barWidth/2,{min:l,max:u}=r.priceRange;if(u-l===0)return;let d=e.E(r),f=d(l),p=Ye(a,o,n.length,r.chartRect.width,e=>n[e].close);if(p.length===0)return;let m=p[0],h=m*s+c,g=d(n[m].close),_=t.createLinearGradient(0,d(u),0,f);_.addColorStop(0,i.areaTopColor),_.addColorStop(1,i.areaBottomColor),t.beginPath(),t.moveTo(h,f),t.lineTo(h,g);let v=h;for(let e=1;e<p.length;e++){let r=p[e];v=r*s+c,t.lineTo(v,d(n[r].close))}t.lineTo(v,f),t.closePath(),t.fillStyle=_,t.fill(),t.beginPath(),t.strokeStyle=i.lineColor,t.lineWidth=i.style?.series.lineWidth??2,t.lineJoin=`round`,t.moveTo(h,g);for(let e=1;e<p.length;e++){let r=p[e];t.lineTo(r*s+c,d(n[r].close))}t.stroke()}},Qe=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange,s=r.barWidth,c=s+r.barSpacing,l=-r.offset+r.chartRect.x+s/2,{min:u,max:d}=r.priceRange;if(d-u===0)return;if(e.f(r)){e.p(t,n,r,i.candleUp,i.candleDown);return}let f=e.E(r);e.v(t,r=>{let{body:u,wick:d}=e.h(s,r.ratio),p=Math.max((u-d)/2,d),m=new Path2D,h=new Path2D;for(let e=a;e<=o&&e<n.length;e++){let t=n[e],i=t.close>=t.open?m:h,a=r.left(e*c+l,d),o=r.y(f(t.high)),s=r.y(f(t.low));i.rect(a,Math.min(o,s),d,Math.max(Math.abs(s-o),d)),i.rect(a-p,r.y(f(t.open))-Math.floor(d/2),p,d),i.rect(a+d,r.y(f(t.close))-Math.floor(d/2),p,d)}t.fillStyle=i.candleUp,t.fill(m),t.fillStyle=i.candleDown,t.fill(h)})}},$e=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange,s=r.barWidth,c=s+r.barSpacing,l=-r.offset+r.chartRect.x+s/2,{min:u,max:d}=r.priceRange;if(d-u===0)return;if(e.f(r)){e.p(t,n,r,i.candleUp,i.candleDown);return}let f=e.E(r);e.v(t,r=>{let{body:u,wick:d}=e.h(s,r.ratio),p=(u-d)/2,m={up:new Path2D,down:new Path2D},h={up:new Path2D,down:new Path2D},g={up:new Path2D,down:new Path2D};for(let e=a;e<=o&&e<n.length;e++){let t=n[e],i=e===0||t.close>=n[e-1].close?`up`:`down`,a=r.left(e*c+l,d),o=a-p,s=r.y(f(t.high)),_=r.y(f(t.low)),v=r.y(f(t.open)),y=r.y(f(t.close)),b=Math.min(v,y),x=Math.max(Math.abs(y-v),d);t.close>=t.open?(b>s&&m[i].rect(a,s,d,b-s),_>b+x&&m[i].rect(a,b+x,d,_-b-x),g[i].rect(o+d/2,b+d/2,Math.max(u-d,0),Math.max(x-d,0))):(m[i].rect(a,Math.min(s,_),d,Math.max(Math.abs(_-s),1)),h[i].rect(o,b,u,x))}for(let e of[`up`,`down`]){let n=e===`up`?i.candleUp:i.candleDown;t.fillStyle=n,t.fill(m[e]),t.fill(h[e]),t.strokeStyle=n,t.lineWidth=d,t.stroke(g[e])}})}},et=32/255,tt=class{baselinePrice=null;setBaseline(e){this.baselinePrice=e}render(t,n,r,i){let{from:a,to:o}=r.visibleRange;if(a>o||n.length===0)return;let s=r.barWidth,c=s/2,l=s+r.barSpacing,u=-r.offset+r.chartRect.x+c,{min:d,max:f}=r.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=e.E(r),h=m(this.baselinePrice??this.computeBaseline(n,a,o)),{chartRect:g}=r,_=[],v=[];for(let e=a;e<=o&&e<n.length;e++)_.push(p(e)),v.push(m(n[e].close));if(_.length<2)return;let y=_.length-1;t.save();let b=m(f),x=m(d),S=new Path2D;S.rect(g.x,Math.min(h,b),g.width,Math.abs(b-h)),t.clip(S);let C=new Path2D;C.moveTo(_[0],h);for(let e=0;e<=y;e++)C.lineTo(_[e],v[e]);C.lineTo(_[y],h),C.closePath(),t.globalAlpha*=et,t.fillStyle=i.candleUp,t.fill(C),t.restore(),t.save();let w=new Path2D;w.rect(g.x,Math.min(h,x),g.width,Math.abs(x-h)),t.clip(w);let T=new Path2D;T.moveTo(_[0],h);for(let e=0;e<=y;e++)T.lineTo(_[e],v[e]);T.lineTo(_[y],h),T.closePath(),t.globalAlpha*=et,t.fillStyle=i.candleDown,t.fill(T),t.restore();let E=new Path2D,D=new Path2D,O=null;for(let e=1;e<=y;e++){let t=r.invertScale?v[e]>=h:v[e]<=h,n=t?E:D;t!==O&&n.moveTo(_[e-1],v[e-1]),O=t,n.lineTo(_[e],v[e])}t.save(),t.lineWidth=i.style?.series.lineWidth??2,t.lineJoin=`round`,t.strokeStyle=i.candleUp,t.stroke(E),t.strokeStyle=i.candleDown,t.stroke(D),t.restore(),t.setLineDash([6,4]),t.strokeStyle=i.textSecondary,t.lineWidth=1;let k=new Path2D;k.moveTo(g.x,h),k.lineTo(g.x+g.width,h),t.stroke(k),t.setLineDash([])}computeBaseline(e,t,n){let r=0,i=0;for(let a=t;a<=n&&a<e.length;a++)r+=e[a].close,i++;return i>0?r/i:0}},nt=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange,s=r.barWidth,c=s/2,l=s+r.barSpacing,u=-r.offset+r.chartRect.x+c,{min:d,max:f}=r.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=e.E(r),h=new Path2D,g=new Path2D,_=new Path2D,v=new Path2D;for(let e=a;e<=o&&e<n.length;e++){let t=n[e],r=p(e),i=t.close>=t.open,a=m(Math.max(t.open,t.close)),o=m(Math.min(t.open,t.close)),l=Math.min(a,o),u=Math.max(Math.abs(o-a),1),d=r-c;i?(h.rect(d,l,s,u),_.rect(d,l,s,u)):(g.rect(d,l,s,u),v.rect(d,l,s,u))}t.fillStyle=i.candleUp,t.fill(h),t.fillStyle=i.candleDown,t.fill(g),t.lineWidth=1,t.strokeStyle=i.candleUp,t.stroke(_),t.strokeStyle=i.candleDown,t.stroke(v)}},rt=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange,s=r.barWidth,c=s/2,l=s+r.barSpacing,u=-r.offset+r.chartRect.x+c,{min:d,max:f}=r.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=e.E(r),h=new Path2D,g=new Path2D;for(let e=a;e<=o&&e<n.length;e++){let t=n[e],r=p(e),i=t.close>=t.open,a=m(t.high),s=m(t.low),c=i?s:a,l=i?h:g;l.moveTo(r,i?a:s),l.lineTo(r,c),e<o&&e+1<n.length&&l.lineTo(p(e+1),c)}t.save(),t.lineJoin=`round`,t.strokeStyle=i.candleUp,t.lineWidth=3,t.stroke(h),t.strokeStyle=i.candleDown,t.lineWidth=1,t.stroke(g),t.restore()}},it=3,at=.8,ot=class{boxSize=1;setBoxSize(e){this.boxSize=e}render(t,n,r,i){let{from:a,to:o}=r.visibleRange,s=r.barWidth,c=s/2,l=s+r.barSpacing,u=-r.offset+r.chartRect.x+c,{min:d,max:f}=r.priceRange,p=f-d;if(p===0||!(this.boxSize>0))return;let m=r.chartRect.height/p,h=e=>e*l+u,g=e.E(r),_=Math.abs(this.boxSize*m);if(_<it){this.renderSolid(t,n,a,o,h,g,Math.max(1,s*at),i);return}let v=Math.min(c*at,_*at)*.5,y=new Path2D,b=new Path2D,x=new Path2D;for(let e=a;e<=o&&e<n.length;e++){let t=n[e],r=h(e),i=t.close>=t.open,a=t.high,o=t.low,s=Math.max(1,Math.round((a-o)/this.boxSize)),c=Math.max(0,Math.floor((d-o)/this.boxSize)-1),l=Math.min(s-1,Math.ceil((f-o)/this.boxSize));for(let e=c;e<=l;e++){let t=g(o+(e+.5)*this.boxSize);i?(y.moveTo(r-v,t-v),y.lineTo(r+v,t+v),b.moveTo(r+v,t-v),b.lineTo(r-v,t+v)):(x.moveTo(r+v,t),x.arc(r,t,v,0,Math.PI*2))}}t.lineWidth=1.5,t.strokeStyle=i.candleUp,t.stroke(y),t.stroke(b),t.strokeStyle=i.candleDown,t.stroke(x)}renderSolid(e,t,n,r,i,a,o,s){for(let c=Math.max(0,n);c<=r&&c<t.length;c++){let n=t[c],r=a(n.high),l=a(n.low);e.fillStyle=n.close>=n.open?s.candleUp:s.candleDown,e.fillRect(i(c)-o/2,Math.min(r,l),o,Math.max(1,Math.abs(l-r)))}}},st=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange,{min:s,max:c}=r.priceRange;if(c-s===0||a>o||n.length===0)return;if(e.f(r)){e.p(t,n,r,i.candleUp,i.candleDown);return}let l=r.barWidth+r.barSpacing,u=-r.offset+r.chartRect.x+r.barWidth/2,d=r.barWidth,f=0;for(let e=a;e<=o&&e<n.length;e++)n[e].volume>f&&(f=n[e].volume);f===0&&(f=1);let p=e=>e*l+u,m=e.E(r);e.v(t,r=>{let{wick:s}=e.h(d,r.ratio),c=new Path2D,l=new Path2D,u=new Path2D,h=new Path2D;for(let t=a;t<=o&&t<n.length;t++){let i=n[t],a=i.close>=i.open,o=r.left(p(t),s),g=r.y(m(i.high)),_=r.y(m(i.low));(a?c:l).rect(o,Math.min(g,_),s,Math.max(Math.abs(_-g),1));let{body:v}=e.h(d*Math.max(.2,i.volume/f),r.ratio),y=r.y(m(i.open)),b=r.y(m(i.close));(a?u:h).rect(o-(v-s)/2,Math.min(y,b),v,Math.max(Math.abs(b-y),s))}t.fillStyle=i.candleUpWick,t.fill(c),t.fillStyle=i.candleDownWick,t.fill(l),t.fillStyle=i.candleUp,t.fill(u),t.fillStyle=i.candleDown,t.fill(h)})}},ct=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange,{min:s,max:c}=r.priceRange;if(c-s===0||a>o||n.length===0)return;let l=r.barWidth+r.barSpacing,u=-r.offset+r.chartRect.x+r.barWidth/2,d=r.barWidth,f=0;for(let e=a;e<=o&&e<n.length;e++)n[e].volume>f&&(f=n[e].volume);f===0&&(f=1);let p=new Path2D,m=new Path2D,h=new Path2D,g=new Path2D,_=e=>e*l+u,v=e.E(r);for(let e=a;e<=o&&e<n.length;e++){let t=n[e],r=e>0?n[e-1]:t,i=_(e),a=v(t.high),o=v(t.low),s=t.close>=r.close,c=d*Math.max(.15,t.volume/f),l=c/2,u=Math.min(a,o),y=Math.max(Math.abs(o-a),1),b=s?p:m,x=s?h:g;b.rect(i-l,u,c,y),x.rect(i-l,u,c,y)}t.fillStyle=lt(i.candleUp,.55),t.fill(p),t.fillStyle=lt(i.candleDown,.55),t.fill(m),t.lineWidth=1,t.strokeStyle=i.candleUpWick,t.stroke(h),t.strokeStyle=i.candleDownWick,t.stroke(g)}};function lt(e,t){if(e.startsWith(`#`)){let n=Math.round(Math.max(0,Math.min(1,t))*255).toString(16).padStart(2,`0`);if(e.length===7)return`${e}${n}`;if(e.length===9)return`${e.slice(0,7)}${n}`}return e}var ut=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange;if(a>o||n.length===0)return;let{min:s,max:c}=r.priceRange;if(c-s===0)return;let l=r.barWidth+r.barSpacing,u=-r.offset+r.chartRect.x+r.barWidth/2,d=e=>e*l+u,f=e.E(r),p=[],m=[];for(let e=a;e<=o&&e<n.length;e++){let t=d(e);p.push({x:t,y:f(n[e].high)}),m.push({x:t,y:f(n[e].low)})}if(p.length===0)return;let h=t.createLinearGradient(0,f(c),0,f(s));h.addColorStop(0,i.areaTopColor),h.addColorStop(1,i.areaBottomColor),t.beginPath(),t.moveTo(p[0].x,p[0].y);for(let e=1;e<p.length;e++)t.lineTo(p[e].x,p[e].y);for(let e=m.length-1;e>=0;e--)t.lineTo(m[e].x,m[e].y);t.closePath(),t.fillStyle=h,t.fill(),t.beginPath(),t.strokeStyle=i.lineColor,t.lineWidth=i.style?.series.lineWidth??2,t.lineJoin=`round`;for(let e=a;e<=o&&e<n.length;e++){let r=d(e),i=f(n[e].close);e===a?t.moveTo(r,i):t.lineTo(r,i)}t.stroke()}},dt=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange;if(a>o||n.length===0)return;let{min:s,max:c}=r.priceRange;if(c-s===0)return;let l=r.barWidth+r.barSpacing,u=-r.offset+r.chartRect.x+r.barWidth/2,d=e=>e*l+u,f=e.E(r);t.beginPath(),t.strokeStyle=i.lineColor,t.lineWidth=i.style?.series.lineWidth??2,t.lineJoin=`miter`;let p=0;for(let e=a;e<=o&&e<n.length;e++){let r=d(e),i=f(n[e].close);e===a?t.moveTo(r,i):(t.lineTo(r,p),t.lineTo(r,i)),p=i}t.stroke()}},ft=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange;if(a>o||n.length===0)return;let{min:s,max:c}=r.priceRange;if(c-s===0)return;let l=r.barWidth+r.barSpacing,u=-r.offset+r.chartRect.x+r.barWidth/2,d=e=>e*l+u,f=e.E(r);t.beginPath(),t.strokeStyle=i.lineColor,t.lineWidth=i.style?.series.lineWidth??2,t.lineJoin=`round`;let p=[];for(let e=a;e<=o&&e<n.length;e++){let r=d(e),i=f(n[e].close);p.push({x:r,y:i}),e===a?t.moveTo(r,i):t.lineTo(r,i)}t.stroke();let m=Math.max(2,Math.min(4,r.barWidth*.3));if(l<m*2)return;let h=new Path2D;for(let{x:e,y:t}of p)h.moveTo(e+m,t),h.arc(e,t,m,0,Math.PI*2);t.fillStyle=i.lineColor,t.fill(h),t.strokeStyle=i.background,t.lineWidth=1,t.stroke(h)}},pt=28,mt=3,ht=class{priceText=null;setPriceText(e){this.priceText=e}render(n,r,i,a){let{from:o,to:s}=i.visibleRange,{min:c,max:l}=i.priceRange;if(l===c)return;if(e.f(i)){e.p(n,r,i,a.candleUp,a.candleDown);return}let u=i.barWidth+i.barSpacing,d=-i.offset+i.chartRect.x+i.barWidth/2,f=e.E(i),p=Math.max(1,Math.round(i.barWidth*.6)),m=i.barWidth>=pt,h=(0,t.autoPricePrecision)(c,l),g=e=>i.formatPrice?.(e)??this.priceText?.(e)??(0,t.formatPrice)(e,h);m&&(n.font=`${a.font.sizeSmall}px ${a.font.family}`,n.textAlign=`center`);for(let e=Math.max(0,o);e<=s&&e<r.length;e++){let t=r[e],i=e*u+d,o=Math.min(f(t.high),f(t.low)),s=Math.max(f(t.high),f(t.low));if(n.fillStyle=t.close>=t.open?a.candleUp:a.candleDown,n.fillRect(Math.round(i-p/2),o,p,Math.max(1,s-o)),!m)continue;let c=f(t.high)<=f(t.low);n.textBaseline=`bottom`,n.fillText(g(c?t.high:t.low),i,o-mt),n.textBaseline=`top`,n.fillText(g(c?t.low:t.high),i,s+mt)}}},gt=t.PHI**-4.5,_t=class{visible=!0;heightRatio=gt;setVisible(e){this.visible=e}isVisible(){return this.visible}setHeightRatio(e){this.heightRatio=Math.max(.05,Math.min(.5,e))}getHeightRatio(){return this.heightRatio}render(n,r,i,a){if(!this.visible||r.length===0)return;let{from:o,to:s}=i.visibleRange,{chartRect:c}=i,l=i.barWidth,u=l+i.barSpacing,d=-i.offset+c.x+l/2,f=0;for(let e=o;e<=s&&e<r.length;e++)r[e].volume>f&&(f=r[e].volume);if(f===0)return;let p=c.y+c.height,m=c.height*this.heightRatio/f;e.v(n,c=>{let f=new Path2D,h=new Path2D,g=c.y(p),_=(e,t,n,r)=>{let i=c.y(p-r*m);g-i>=1&&e.rect(t,i,n,g-i)};if(e.f(i))e.d(r,o,s,e=>e*u+d,e=>{let t=c.x(e.x);_(e.close>=e.open?f:h,t,Math.max(1,c.x(e.x+1)-t),e.volume)});else{let{body:t,wick:n}=e.h(l,c.ratio),i=(t-n)/2;for(let e=o;e<=s&&e<r.length;e++){let a=r[e];_(a.close>=a.open?f:h,c.left(e*u+d,n)-i,t,a.volume)}}let v=(0,t.resolveVolumeColors)(a);n.fillStyle=v.up,n.fill(f),n.fillStyle=v.down,n.fill(h)})}},vt=.32;function yt(e){return Number.isFinite(e)?vt*Math.min(1,Math.max(0,e)):vt}var bt=class{visible=!1;buckets=48;widthRatio=.18;opacity=vt;highlightPoC=!0;setVisible(e){this.visible=e}isVisible(){return this.visible}setBuckets(e){this.buckets=Math.max(8,Math.min(200,Math.floor(e)))}setWidthRatio(e){this.widthRatio=Math.max(.05,Math.min(.5,e))}setOpacity(e){this.opacity=Math.max(.05,Math.min(1,e))}setHighlightPoC(e){this.highlightPoC=e}render(t,n,r,i){if(!this.visible||n.length===0)return;let{from:a,to:o}=r.visibleRange,{chartRect:s,priceRange:c}=r,l=c.max-c.min;if(l<=0)return;let u=new Float64Array(this.buckets),d=new Float64Array(this.buckets),f=new Float64Array(this.buckets);for(let e=a;e<=o&&e<n.length;e++){let t=n[e];if(t.volume<=0)continue;let r=Math.max(t.low,c.min),i=Math.min(t.high,c.max);if(i<=r)continue;let a=(r-c.min)/l,o=(i-c.min)/l,s=Math.max(0,Math.floor(a*this.buckets)),p=Math.min(this.buckets-1,Math.floor(o*this.buckets)),m=Math.max(1,p-s+1),h=t.volume/m,g=t.close>=t.open;for(let e=s;e<=p;e++)u[e]+=h,g?d[e]+=h:f[e]+=h}let p=0,m=-1;for(let e=0;e<u.length;e++)u[e]>p&&(p=u[e],m=e);if(p===0)return;let h=s.width*this.widthRatio,g=s.x+s.width,_=e.E(r),v=1/p;t.save(),t.globalAlpha=this.opacity;for(let n=0;n<this.buckets;n++){let a=u[n];if(a===0)continue;let o=e.w(n,this.buckets,r,_),c=a*v*h,l=d[n]*v*h,p=f[n]*v*h;l>0&&(t.fillStyle=i.candleUp,t.fillRect(g-l,o.top+.5,l,o.height-1)),p>0&&(t.fillStyle=i.candleDown,t.fillRect(g-c,o.top+.5,p,o.height-1)),this.highlightPoC&&n===m&&(t.globalAlpha=1,t.strokeStyle=i.crosshair,t.lineWidth=1,t.setLineDash([3,2]),t.beginPath(),t.moveTo(s.x,o.mid+.5),t.lineTo(g-c-2,o.mid+.5),t.stroke(),t.setLineDash([]),t.globalAlpha=this.opacity)}t.restore()}},xt={session:`1d`,week:`1w`,month:`1M`},St=6e4,Ct=864e5,wt={},Tt=1.5;function Et(e){return e===`session`||e===`week`||e===`month`}function Dt(e,n,r){let i=Et(n)?xt[n]:n,a=(0,t.barTimeUnit)(e),o=r&&!(0,t.isUtcTimeZone)(r)&&(0,t.timeframeFollowsDays)(i)&&(0,t.isValidTimeZone)(r)?r:null,s=o===null?wt:{timeZone:o},c=o!==null&&(0,t.barsAreDaily)(e)===!0,l=(0,t.timeframeToMs)(i),u=(Number.isFinite(l)?l:St)*Tt,d=NaN,f=NaN,p=NaN,m=!1;return e=>{let n=e*a,r=c&&n%Ct===0;if(n>=d&&n<f&&r===m)return p;m=r;let l=r?wt:s;return d=(0,t.timeframeBucketStart)(n,i,l),f=(0,t.timeframeBucketStart)(d+u,i,l),p=o===null||r?d:(0,t.timeframeBucketStart)(n+(0,t.zoneOffsetMinutes)(o,n)*St,i),p}}function Ot(e,t,n){let r=e[t]?.[n];return e[t-1]?.[n]!==r&&e[t+1]?.[n]!==r}function kt(e,t,n,r=`session`){return e[t]?.[r]===e[n]?.[r]?!1:!(Ot(e,t,r)&&Ot(e,n,r))}function At(e,t){return e<0?0:e>t?t:e}function jt(e,t,n,r={}){let i=Math.max(4,Math.min(500,Math.floor(r.buckets??48))),a=n-t;if(a<=0||e.length===0)return null;let o=a/i,s=new Float64Array(i);for(let r of e){let e=Math.min(r.low,r.high),a=Math.max(r.low,r.high);if(a<t||e>n)continue;let c=At(Math.floor((e-t)/o),i-1),l=At(Math.floor((a-t)/o),i-1);for(let e=c;e<=l;e++)s[e]+=1}let c=0,l=0,u=0;for(let e=0;e<i;e++)u+=s[e],s[e]>l&&(l=s[e],c=e);if(u===0)return null;let d=u*(r.valueAreaPct??.7),f=c,p=c,m=s[c];for(;m<d&&(f>0||p<i-1);){let e=f>0?s[f-1]:-1;(p<i-1?s[p+1]:-1)>=e?(p+=1,m+=s[p]):(--f,m+=s[f])}let h=[];for(let e=0;e<i;e++){let n=t+e*o;h.push({low:n,high:n+o,mid:n+o/2,count:s[e]})}return{buckets:h,pocIndex:c,maxCount:l,totalCount:u,valueAreaLow:t+f*o,valueAreaHigh:t+(p+1)*o}}function Mt(e){let t=(e%52+52)%52;return t<26?String.fromCharCode(65+t):String.fromCharCode(97+t-26)}function Nt(e,t,n,r=48){let i=Math.max(4,Math.min(500,Math.floor(r))),a=n-t,o=Array.from({length:i},()=>[]);if(a<=0)return o;let s=a/i;return e.forEach((e,r)=>{let a=Math.min(e.low,e.high),c=Math.max(e.low,e.high);if(c<t||a>n)return;let l=Math.max(0,Math.min(i-1,Math.floor((a-t)/s))),u=Math.max(0,Math.min(i-1,Math.floor((c-t)/s)));for(let e=l;e<=u;e++)o[e].push(r)}),o}function Pt(e,t,n,r={},i){if(e.length===0||n-t<=0)return[];let a=[],o=Dt(e,`session`,i),s=0,c=o(e[0].time),l=(i,o,s)=>{let c=jt(e.slice(i,o+1),t,n,r);c&&a.push({startIndex:i,endIndex:o,startTime:s,profile:c})};for(let t=1;t<e.length;t++){let n=o(e[t].time);n!==c&&(l(s,t-1,c),s=t,c=n)}return l(s,e.length-1,c),a}var Ft=class{visible=!1;buckets=48;widthRatio=.18;opacity=.32;valueAreaPct=.7;highlightPoC=!0;showStats=!0;splitBySession=!1;letters=!1;lastStats=null;exchangeZone=null;setVisible(e){this.visible=e,e||(this.lastStats=null)}isVisible(){return this.visible}setBuckets(e){this.buckets=Math.max(8,Math.min(200,Math.floor(e)))}setWidthRatio(e){this.widthRatio=Math.max(.05,Math.min(.5,e))}setOpacity(e){this.opacity=Math.max(.05,Math.min(1,e))}setValueAreaPct(e){this.valueAreaPct=Math.max(.3,Math.min(.95,e))}setHighlightPoC(e){this.highlightPoC=e}setShowStats(e){this.showStats=e}setSplitBySession(e){this.splitBySession=e}isSplitBySession(){return this.splitBySession}getConfig(){let{buckets:e,widthRatio:t,opacity:n,valueAreaPct:r,highlightPoC:i,showStats:a,splitBySession:o,letters:s}=this;return{buckets:e,widthRatio:t,opacity:n,valueAreaPct:r,highlightPoC:i,showStats:a,splitBySession:o,letters:s}}setExchangeTimeZone(e){this.exchangeZone=e}setLetters(e){this.letters=e}drawsText(){return this.splitBySession?this.letters:this.showStats}getStats(){return this.lastStats}render(t,n,r,i){if(!this.visible||n.length===0)return;let{from:a,to:o}=r.visibleRange,{chartRect:s,priceRange:c}=r,l=Math.max(0,a),u=Math.min(o,n.length-1);if(u<l)return;let d=n.slice(l,u+1);if(this.splitBySession){this.lastStats=null,this.renderSplit(t,d,l,r,i);return}let f=jt(d,c.min,c.max,{buckets:this.buckets,valueAreaPct:this.valueAreaPct});if(!f){this.lastStats=null;return}let p=f.buckets[f.pocIndex].mid;this.lastStats={poc:p,vah:f.valueAreaHigh,val:f.valueAreaLow,valueAreaPct:this.valueAreaPct};let m=f.buckets.length,h=s.width*this.widthRatio,g=s.x,_=e.E(r),v=1/f.maxCount;t.save();for(let n=0;n<m;n++){let a=f.buckets[n];if(a.count===0)continue;let o=e.w(n,m,r,_),s=a.count*v*h,c=a.mid>=f.valueAreaLow&&a.mid<=f.valueAreaHigh;t.globalAlpha=c?Math.min(1,this.opacity+.18):this.opacity,t.fillStyle=c?i.candleUp:i.textSecondary,t.fillRect(g,o.top+.5,s,o.height-1)}t.globalAlpha=.6,t.strokeStyle=i.candleUp,t.lineWidth=1,t.setLineDash([1,3]);for(let e of[f.valueAreaHigh,f.valueAreaLow]){let n=_(e);t.beginPath(),t.moveTo(g,Math.round(n)+.5),t.lineTo(s.x+s.width,Math.round(n)+.5),t.stroke()}if(t.setLineDash([]),this.highlightPoC){let e=_(p);t.globalAlpha=1,t.strokeStyle=i.crosshair,t.lineWidth=1,t.setLineDash([3,2]),t.beginPath(),t.moveTo(g,Math.round(e)+.5),t.lineTo(s.x+s.width,Math.round(e)+.5),t.stroke(),t.setLineDash([])}this.showStats&&this.drawStats(t,s.x+6,s.y+6,p,f.valueAreaHigh,f.valueAreaLow,r,i),t.restore()}renderSplit(t,n,r,i,a){let{chartRect:o,priceRange:s}=i,c=Pt(n,s.min,s.max,{buckets:this.buckets,valueAreaPct:this.valueAreaPct},this.exchangeZone);if(c.length===0)return;let l=e.E(i),u=i.barWidth/2;t.save();for(let d of c){let c=d.profile,f=c.buckets.length,p=o.height/f,m=e.b(r+d.startIndex,i)-u,h=e.b(r+d.endIndex,i)+u,g=Math.max(2,h-m),_=1/c.maxCount,v=this.letters&&p>=7,y=v?Nt(n.slice(d.startIndex,d.endIndex+1),s.min,s.max,this.buckets):null;if(v&&y){t.font=`${Math.min(11,Math.floor(p))}px ui-monospace, monospace`,t.textBaseline=`middle`,t.textAlign=`left`;let n=Math.max(1,Math.floor(g/6));for(let r=0;r<f;r++){let o=y[r];if(o.length===0)continue;let s=e.w(r,f,i,l).mid,u=c.buckets[r].mid>=c.valueAreaLow&&c.buckets[r].mid<=c.valueAreaHigh;t.globalAlpha=u?.95:.6,t.fillStyle=u?a.candleUp:a.textSecondary;let d=Math.min(o.length,n);for(let e=0;e<d;e++)t.fillText(Mt(o[e]),m+e*6,s)}}else for(let n=0;n<f;n++){let r=c.buckets[n];if(r.count===0)continue;let o=e.w(n,f,i,l),s=r.count*_*g,u=r.mid>=c.valueAreaLow&&r.mid<=c.valueAreaHigh;t.globalAlpha=u?Math.min(1,this.opacity+.18):this.opacity,t.fillStyle=u?a.candleUp:a.textSecondary,t.fillRect(m,o.top+.5,s,o.height-1)}if(this.highlightPoC){let e=l(c.buckets[c.pocIndex].mid);t.globalAlpha=1,t.strokeStyle=a.crosshair,t.lineWidth=1,t.setLineDash([3,2]),t.beginPath(),t.moveTo(m,Math.round(e)+.5),t.lineTo(Math.min(h,o.x+o.width),Math.round(e)+.5),t.stroke(),t.setLineDash([])}}t.restore()}drawStats(e,n,r,i,a,o,s,c){let l=s.pricePrecision??It(i),u=e=>(0,t.priceTagText)(e,s,l),d=[[`POC`,u(i),c.text],[`VAH`,u(a),c.candleUp],[`VAL`,u(o),c.candleUp]];e.globalAlpha=1,e.font=`600 10px ${c.font.family}`,e.textBaseline=`middle`;let f=0;for(let[,t]of d)f=Math.max(f,e.measureText(t).width);let p=38+f,m=6+d.length*14;e.fillStyle=c.background,e.globalAlpha=.82,Lt(e,n,r,p,m,4),e.fill(),e.globalAlpha=1,d.forEach(([t,i,a],o)=>{let s=r+6/2+14/2+o*14;e.fillStyle=a,e.textAlign=`left`,e.fillText(t,n+6,s),e.fillStyle=c.text,e.textAlign=`right`,e.fillText(i,n+p-6,s)}),e.textAlign=`left`}};function It(e){let t=Math.abs(e);return t>=1e3?2:t>=1?4:6}function Lt(e,t,n,r,i,a){e.beginPath(),e.moveTo(t+a,n),e.arcTo(t+r,n,t+r,n+i,a),e.arcTo(t+r,n+i,t,n+i,a),e.arcTo(t,n+i,t,n,a),e.arcTo(t,n,t+r,n,a),e.closePath()}function Rt(e,t,n){let r=Dt(e,t===`day`?`session`:`week`,n),i=[];for(let t of e){let e=r(t.time),n=i[i.length-1];n&&n.key===e?(n.high=Math.max(n.high,t.high),n.low=Math.min(n.low,t.low),n.close=t.close):i.push({key:e,open:t.open,high:t.high,low:t.low,close:t.close})}return i}function zt(e,t=`day`,n){let r=Rt(e,t,n);if(r.length<2)return[];let i=r[r.length-2],a=r[r.length-1],o=t===`day`?`D`:`W`;return[{id:`p${o}h`,label:`P${o}H`,price:i.high},{id:`p${o}c`,label:`P${o}C`,price:i.close},{id:`p${o}l`,label:`P${o}L`,price:i.low},{id:`open`,label:t===`day`?`Day Open`:`Week Open`,price:a.open}]}var Bt=class{visible=!1;period=`day`;exchangeZone=null;setVisible(e){this.visible=e}isVisible(){return this.visible}setPeriod(e){this.period=e}getPeriod(){return this.period}setExchangeTimeZone(e){this.exchangeZone=e}render(t,n,r,i){if(!this.visible||n.length===0)return;let a=zt(n,this.period,this.exchangeZone);if(a.length===0)return;let{chartRect:o}=r,s=o.y,c=o.y+o.height;t.save(),t.font=`600 10px ${i.font.family}`,t.textBaseline=`middle`;for(let n of a){let a=e.T(n.price,r);if(a<s||a>c)continue;let l=Vt(n,i);t.strokeStyle=l,t.globalAlpha=.7,t.lineWidth=1,t.setLineDash([5,4]),t.beginPath(),t.moveTo(o.x,Math.round(a)+.5),t.lineTo(o.x+o.width,Math.round(a)+.5),t.stroke(),t.setLineDash([]),t.globalAlpha=1;let u=n.label,d=t.measureText(u).width,f=o.x+o.width-d-10;t.fillStyle=i.background,t.globalAlpha=.85,O(t,f-4,a-7,d+8,14,i),t.globalAlpha=1,t.fillStyle=l,t.textAlign=`left`,t.fillText(u,f,a+.5)}t.restore()}};function Vt(e,t){return e.id.endsWith(`h`)?t.candleUp:e.id.endsWith(`l`)?t.candleDown:t.textSecondary}function Ht(e){let t,n;return e.map(e=>{let r;return e.type===`high`?(r=t===void 0||e.price>t?`HH`:`LH`,t=e.price):(r=n===void 0||e.price<n?`LL`:`HL`,n=e.price),{...e,label:r}})}function Ut(e,t=5,n=5){let r=Math.max(1,Math.floor(t)),i=Math.max(1,Math.floor(n)),a=[];for(let t=r;t<e.length-i;t++){let n=e[t].high,o=e[t].low,s=!0,c=!0;for(let a=t-r;a<=t+i&&!(a!==t&&(e[a].high>=n&&(s=!1),e[a].low<=o&&(c=!1),!s&&!c));a++);s?a.push({index:t,price:n,type:`high`}):c&&a.push({index:t,price:o,type:`low`})}return a}var Wt=4,Gt=10,Kt=class{visible=!1;left=5;right=5;showLabels=!1;structureLabels=!1;setVisible(e){this.visible=e}isVisible(){return this.visible}setStrength(e,t){this.left=Math.max(1,Math.floor(e)),this.right=Math.max(1,Math.floor(t))}setShowLabels(e){this.showLabels=e}setStructureLabels(e){this.structureLabels=e}getConfig(){return{left:this.left,right:this.right,showLabels:this.showLabels,structureLabels:this.structureLabels}}render(t,n,r,i){if(!this.visible||n.length===0)return;let a=Ut(n,this.left,this.right);if(a.length===0)return;let o=this.structureLabels?Ht(a):a,{from:s,to:c}=r.visibleRange;t.save(),t.font=`10px ${i.font.family}`,t.textAlign=`center`;for(let n of o){if(n.index<s-1||n.index>c+1)continue;let a=e.b(n.index,r),o=e.T(n.price,r),l=n.type===`high`,u=l?i.candleDown:i.candleUp,d=l!==(r.invertScale===!0),f=d?o-8:o+8;t.fillStyle=u,t.beginPath(),d?(t.moveTo(a-5,f-5),t.lineTo(a+5,f-5),t.lineTo(a,f)):(t.moveTo(a-5,f+5),t.lineTo(a+5,f+5),t.lineTo(a,f)),t.closePath(),t.fill();let p=this.structureLabels&&`label`in n?String(n.label):this.showLabels?qt(n.price,r):null;p&&(t.textBaseline=d?`bottom`:`top`,t.fillText(p,a,d?f-5-1:f+5+1))}t.restore()}};function qt(e,n){return(0,t.priceTagText)(e,n,n.pricePrecision??Jt(e))}function Jt(e){let t=Math.abs(e);return t>=1?2:t===0?Wt-1:Math.min(Gt,Wt-1-Math.floor(Math.log10(t)))}function Yt(e){if(e.length<2)return 0;let t=e.map(e=>e.price).sort((e,t)=>e-t),n=[];for(let e=1;e<t.length;e++){let r=t[e]-t[e-1];r>0&&n.push(r)}return n.length===0?0:(n.sort((e,t)=>e-t),n[Math.floor(n.length/2)])}var Xt=class{buffer=[];constructor(e=240){this.capacity=e,this.capacity=Math.max(1,Math.floor(e))}push(e,t){let n={time:e,bids:t.bids.map(e=>({...e})),asks:t.asks.map(e=>({...e})),bidStep:Yt(t.bids),askStep:Yt(t.asks)},r=this.indexAfter(e);if(r>0&&this.buffer[r-1].time===e){this.buffer[r-1]=n;return}this.buffer.splice(r,0,n),this.buffer.length>this.capacity&&(this.buffer=this.buffer.slice(this.buffer.length-this.capacity))}indexAfter(e){let t=this.buffer;if(t.length===0||t[t.length-1].time<=e)return t.length;let n=0,r=t.length;for(;n<r;){let i=n+r>>1;t[i].time<=e?n=i+1:r=i}return n}snapshots(){return this.buffer}maxVolume(){let e=0;for(let t of this.buffer){for(let n of t.bids)n.volume>e&&(e=n.volume);for(let n of t.asks)n.volume>e&&(e=n.volume)}return e}getCapacity(){return this.capacity}setCapacity(e){this.capacity=Math.max(1,Math.floor(e)),this.buffer.length>this.capacity&&(this.buffer=this.buffer.slice(this.buffer.length-this.capacity))}clear(){this.buffer=[]}get size(){return this.buffer.length}},Zt=class{buffer=new Xt(240);visible=!1;opacity=.7;setVisible(e){this.visible=e}isVisible(){return this.visible}setOpacity(e){this.opacity=Math.max(.1,Math.min(1,e))}setCapacity(e){this.buffer.setCapacity(e)}getConfig(){return{opacity:this.opacity,capacity:this.buffer.getCapacity()}}push(e,t){this.buffer.push(e,t)}clear(){this.buffer.clear()}render(t,n,r){if(!this.visible)return;let i=this.buffer.snapshots();if(i.length===0)return;let a=this.buffer.maxVolume();if(a<=0)return;let o=1/a,{chartRect:s}=n,c=Math.max(2,n.barWidth+n.barSpacing),l=s.x,u=s.x+s.width,d=s.y,f=s.y+s.height;t.save();for(let a of i){let i=e.O(a.time,n);if(i<l-c||i>u+c)continue;let s=i-c/2;this.drawSide(t,a.bids,a.bidStep??Yt(a.bids),r.candleUp,s,c,n,o,d,f),this.drawSide(t,a.asks,a.askStep??Yt(a.asks),r.candleDown,s,c,n,o,d,f)}t.restore()}drawSide(t,n,r,i,a,o,s,c,l,u){if(n.length===0)return;let d=Qt(Math.min(n[0].price,n[n.length-1].price),r,s);t.fillStyle=i;for(let r of n){let n=e.T(r.price,s);n<l-d||n>u+d||(t.globalAlpha=Math.min(1,Math.sqrt(r.volume*c))*this.opacity,t.fillRect(a,n-d/2,o,d))}t.globalAlpha=1}};function Qt(t,n,r){if(!(n>0))return 3;let i=Math.abs(e.T(t,r)-e.T(t+n,r));return Math.max(2,Math.min(i,12))}var $t=class{series=new Map;set(e,n){if(!n||n.length===0){this.series.delete(e);return}let r=[...n].sort((e,t)=>e.time-t.time),i=(0,t.barTimeUnit)(r),a=r.map(e=>e.time*i),o=a[a.length-1],s=a.length>1?o-a[a.length-2]:0;this.series.set(e,{bars:r,times:a,end:o+s})}has(e){return this.series.has(e)}get(e){return this.series.get(e)?.bars}symbols(){return[...this.series.keys()]}closeAt(e,n,r){let i=this.series.get(e);if(!i)return;let a=(0,t.normalizeBarTime)(n,r),{times:o,bars:s}=i;if(a<o[0])return;let c=o.length-1;if(a>o[c]&&(i.end<=o[c]||a>=i.end))return;let l=0,u=c;for(;l<u;){let e=l+u+1>>1;o[e]<=a?l=e:u=e-1}return s[l].close}lastCloseAt(e,n,r){let i=this.closeAt(e,n,r);if(i!==void 0)return{close:i,stale:!1};let a=this.series.get(e);if(!(!a||(0,t.normalizeBarTime)(n,r)<a.times[0]))return{close:a.bars[a.bars.length-1].close,stale:!0}}},en=11,tn={mark:11,label:12,letter:13,text:14},nn={mark:0,label:1,letter:2,text:3},rn=12,an=.12,on=`#131416`,sn=`#1fa874`,cn=`#e8505b`,ln=`#e6e3dc`;function un(e){let n=e?.font,r=n?.sizeSmall??en,i=e=>Math.max(tn[e],r+nn[e]),a=e?.background??on;return{sizes:{mark:i(`mark`),label:i(`label`),letter:i(`letter`),text:i(`text`)},figures:n?.family||t.DEFAULT_FONT_FAMILY,prose:n?.textFamily||t.SANS_FONT_FAMILY,background:a,ink:e?.text??ln,handleFill:e?.style?.drawings?.handle??a,scale:Math.max(1,r/en),rise:e?.style?.trading?.profit??sn,fall:e?.style?.trading?.loss??cn}}var dn=un(null),fn=null,pn=!1;function mn(){pn=!0,fn=null}function hn(e,t,n,r){pn&&(fn=fn?{x0:Math.min(fn.x0,e),y0:Math.min(fn.y0,t),x1:Math.max(fn.x1,e+n),y1:Math.max(fn.y1,t+r)}:{x0:e,y0:t,x1:e+n,y1:t+r})}function gn(){pn=!1;let e=fn;return fn=null,e?{x:e.x0,y:e.y0,width:e.x1-e.x0,height:e.y1-e.y0}:null}var _n=null;function vn(e){_n=e}var yn=4;function bn(e,t,n,r){if(!_n)return{left:e,top:t};let i=_n.x+_n.width-yn-n,a=_n.y+_n.height-yn-r;return{left:Math.max(_n.x+yn,Math.min(e,i)),top:Math.max(_n.y+yn,Math.min(t,a))}}function xn(e){dn=un(e)}function M(){return dn}function N(e,t={}){return`${t.weight?`${t.weight} `:``}${dn.sizes[e]}px ${t.prose?dn.prose:dn.figures}`}function Sn(e,t=`text`){let n=e.fontSize;return n&&n!==rn?n:dn.sizes[t]}function Cn(e){return wn+Tn*Math.max(1,Number.isFinite(e)?e:1)}var wn=9,Tn=3,En=new Map,Dn=64,On=4.5;function kn(e){let n=`${e}|${dn.background}|${dn.ink}`,r=En.get(n);return r===void 0&&(En.size>=Dn&&En.clear(),r=(0,t.readableOn)(e,dn.background,dn.ink,On),En.set(n,r)),r}function An(e,t=dn.scale){return Math.min(Nn,jn+Mn*(Math.max(1,Number.isFinite(e)?e:1)-1))*t}var jn=4.5,Mn=.75,Nn=8;function Pn(e,t){let n=Math.max(1,t);switch(e){case`dashed`:return[Math.max(5,3*n),Math.max(4,2*n)];case`dotted`:return[0,Math.max(3,2.5*n)];case`guide`:return[3,3];default:return[]}}function P(e,n=an){return(0,t.ownFillColor)(e)??(0,t.withAlpha)(e.color,n)}function Fn(e){return(0,t.ownFillColor)(e)!==void 0}function In(e){return(0,t.inkOn)(e,`#0b0d10`,`#ffffff`)}var Ln=`rgba(12, 16, 22, 0.85)`,Rn=Ln;function zn(e){Rn=e?.background??Ln,xn(e)}function Bn(){return M().handleFill}function F(e,t,n,r,i=Rn){e.save(),e.lineJoin=`round`,e.lineWidth=Vn,e.strokeStyle=i,e.setLineDash([]),e.strokeText(t,n,r),e.restore(),e.fillText(t,n,r)}var Vn=4,Hn=()=>M().sizes.label,Un=4,Wn=3,Gn=[],Kn=[],qn=!1;function Jn(e){Gn=e??[],Kn=[],qn=e!==null}function Yn(e,t,n,r){qn&&Kn.push({x:e,y:t,width:n-e,height:r-t})}function Xn(e,t,n,r,i){return r>e.x&&t<e.x+e.width&&i>e.y&&n<e.y+e.height}function Zn(e,t,n,r){return Gn.some(i=>Xn(i,e,t,n,r))}function Qn(e,t,n,r){return Zn(e,t,n,r)||Kn.some(i=>Xn(i,e,t,n,r))}function $n(e,t,n){let r=n;for(let n of[...Gn,...Kn])t>n.x&&e<n.x+n.width&&(r=Math.max(r,n.y+n.height));return r}function er(e,t){let n=null;for(let r of[...Gn,...Kn])t>r.y&&e<r.y+r.height&&(n=Math.max(n??r.x+r.width,r.x+r.width));return n}var tr=()=>2*Hn();function nr(e,t,n,r,i=n,a=-1/0){e.font=N(`label`);let o=e.measureText(t).width,s=rr(n,i,r,o,a);e.textAlign=s.align,e.textBaseline=s.baseline,F(e,t,s.x,s.y),Yn(s.left,s.top,s.left+o,s.top+Hn())}function rr(e,t,n,r,i){let a=e+Un,o=t-Un-r,s=o>a?[a,o]:[a],c={top:n-Wn-Hn(),bottom:n-Wn},l={top:n+Wn,bottom:n+Wn+Hn()};for(let e of[c,l])if(!(e.top<i)){for(let t of s)if(!Qn(t,e.top,t+r,e.bottom)){let n=e===c;return{x:t,y:n?e.bottom:e.top,align:`left`,baseline:n?`bottom`:`top`,left:t,top:e.top}}}let u=s.map(e=>({l:e,top:$n(e,e+r,n)+Wn})),d=u.find(e=>e.top-n<=tr());if(d)return{x:d.l,y:d.top,align:`left`,baseline:`top`,left:d.l,top:d.top};let f=t-Un,p={left:f-r,top:n-Hn()/2};if(!Qn(p.left,p.top,f,p.top+Hn()))return{x:f,y:n,align:`right`,baseline:`middle`,...p};let m=u.reduce((e,t)=>t.top<e.top?t:e);return{x:m.l,y:m.top,align:`left`,baseline:`top`,left:m.l,top:m.top}}function ir(){return Math.round(M().sizes.label*ar)}var ar=1.5,or=4,sr=6;function cr(e,t){return Math.ceil(e.measureText(t).width)+2*sr}function lr(e,t,n,r,i,a=In(i)){let o=cr(e,t),s=ir(),c=Math.round(r-s/2);return hn(Math.round(n),c,o,s),e.fillStyle=i,e.beginPath(),typeof e.roundRect==`function`?e.roundRect(Math.round(n),c,o,s,or):e.rect(Math.round(n),c,o,s),e.fill(),e.fillStyle=a,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(t,Math.round(n)+sr,c+s/2+.5),o}var ur=1.35,dr=8,fr=5,pr=4,mr=.94,hr=.16,gr=6e4,_r=60*gr,vr=24*_r;function yr(e){let t=Math.abs(e);return t>=10||t===0?2:t>=1?4:Math.min(10,Math.ceil(-Math.log10(t))+3)}var br=2;function xr(e,n=e,r){return r?(0,t.priceTagText)(e,r,r.pricePrecision??yr(n)):e.toFixed(yr(n))}function Sr(e,n){return n?(0,t.formatPrice)(e,br,n.numberLocale??`en-US`):e.toFixed(br)}function Cr(e,t,n){let r=t-e,i=e===0?0:r/e*100,a=r>=0?`+`:``;return`${a}${xr(r,e,n)} (${a}${Sr(i,n)}%)`}function wr(e){let t=Math.abs(e);if(t<_r)return`${Math.round(t/gr)}m`;if(t<vr){let e=Math.floor(t/_r),n=Math.round((t-e*_r)/gr);return n>0?`${e}h ${n}m`:`${e}h`}let n=Math.floor(t/vr),r=Math.round((t-n*vr)/_r);if(n>=7){let e=Math.floor(n/7),t=n-e*7;return t>0?`${e}w ${t}d`:`${e}w`}return r>0?`${n}d ${r}h`:`${n}d`}function Tr(e){return!!e.data&&e.data.length>0}function Er(t,n,r,i){let a=e.D(t.anchors[n].time,i),o=e.D(t.anchors[r].time,i);return Math.round(Math.abs(o-a))}function Dr(e,t,n,r){return Tr(r)?wr(e.anchors[n].time-e.anchors[t].time):null}function Or(e,t,n,r,i=`center`,a=!0){let o=M();e.font=N(`label`);let s=Math.round(o.sizes.label*ur),c=0;for(let n of t)c=Math.max(c,e.measureText(n).width);let l=Math.ceil(c+dr*2),u=t.length*s+fr*2,d=bn(i===`left`?n:i===`right`?n-l:n-l/2,a?r-u:r,l,u),f=Math.round(d.left),p=Math.round(d.top);kr(e,f,p,l,u),e.fillStyle=o.ink,e.textAlign=`left`,e.textBaseline=`top`;for(let n=0;n<t.length;n++)e.fillText(t[n],f+dr,p+fr+n*s+(s-o.sizes.label)/2);return{x:f,y:p,width:l,height:u}}function kr(e,n,r,i,a){let o=M(),s=Math.round(n),c=Math.round(r),l=Math.round(i),u=Math.round(a);hn(s,c,l,u),e.beginPath(),typeof e.roundRect==`function`?e.roundRect(s+.5,c+.5,l-1,u-1,pr):e.rect(s+.5,c+.5,l-1,u-1),e.fillStyle=(0,t.withAlpha)(o.background,mr),e.fill(),e.strokeStyle=(0,t.withAlpha)(o.ink,hr),e.lineWidth=1,e.setLineDash([]),e.stroke()}function Ar(e,t){return e.find(e=>!Zn(e.left,e.top,e.right,e.bottom)&&t.every(t=>e.right<=t.left||t.right<=e.left||e.bottom<=t.top||t.bottom<=e.top))??null}function jr(e,t,n){let r=Math.abs(e.anchors[t[1]].price-e.anchors[t[0]].price),i=Math.abs(e.anchors[n[1]].price-e.anchors[n[0]].price);return i===0?`—`:(r/i).toFixed(3)}var Mr=4,Nr=10,Pr=3,Fr=14,Ir=8,Lr=2,Rr=3,zr=4,Br=2,Vr=(e,t)=>e.left<t.right&&t.left<e.right&&e.top<t.bottom&&t.top<e.bottom,Hr=class{symbols=new Map;mode=`percent`;store=new $t;aligned=new Map;reservedLevels=()=>[];setReservedLevels(e){this.reservedLevels=e}setMode(e){this.mode=e}getMode(){return this.mode}addSymbol(e){this.symbols.set(e.id,e),this.store.set(e.id,e.data),this.aligned.delete(e.id)}removeSymbol(e){this.symbols.delete(e),this.store.set(e,null),this.aligned.delete(e)}setSymbolData(e,t){let n=this.symbols.get(e);n&&(n.data=t,this.store.set(e,t),this.aligned.delete(e))}setSymbolVisible(e,t){let n=this.symbols.get(e);n&&(n.visible=t)}getSymbols(){return Array.from(this.symbols.values())}clear(){for(let e of this.symbols.keys())this.store.set(e,null);this.symbols.clear(),this.aligned.clear()}getPriceRange(e,t){let n=1/0,r=-1/0;for(let i of this.symbols.values()){if(!i.visible||i.data.length===0)continue;let a=this.line(i,e,t);if(a)for(let e=a.from;e<=a.to;e++){let t=a.priceAt(e);t!==null&&(t<n&&(n=t),t>r&&(r=t))}}return n<=r?{min:n,max:r}:null}render(e,t,n,r){if(this.symbols.size===0||t.length===0)return;let{chartRect:i}=n;e.save(),e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.clip();let a=[];for(let r of this.symbols.values()){if(!r.visible||r.data.length===0)continue;let i=this.renderSymbol(e,r,t,n);i&&a.push({sym:r,...i})}this.renderLabels(e,a,n,r),e.restore()}renderLabels(e,t,n,r){if(t.length===0)return;e.font=`bold ${Nr}px sans-serif`,e.textBaseline=`middle`,e.textAlign=`right`;let i=this.reservedBoxes(n);for(let a of t){let o=Ir+Rr+e.measureText(a.sym.label).width+2*Pr,s=this.placeLabel(a,o,i,t,n.chartRect);i.push(s),this.drawLabel(e,a.sym,s,r)}}drawLabel(e,t,n,r){let i=(n.top+n.bottom)/2,a=n.left+Pr;e.strokeStyle=t.color,e.lineWidth=Lr,e.beginPath(),e.moveTo(a,i),e.lineTo(a+Ir,i),e.stroke(),e.fillStyle=r.text,F(e,t.label,n.right-Pr,i,r.background)}placeLabel(e,t,n,r,i){let a=e.x-Mr,o=e=>({left:a-t,top:e,right:a,bottom:e+Fr}),s=e.y-Mr-Fr,c=e.y+Mr,l=Array.from({length:zr},(e,t)=>[o(s-t*Fr),o(c+t*Fr)]).flat(),u=i.y+i.height,d=e=>e.top>=i.y&&e.bottom<=u&&!n.some(t=>Vr(t,e)),f=t=>{let n=(t.top+t.bottom)/2,i=t=>Math.hypot(t.x-e.x,t.y-n);return r.every(t=>t===e||i(t)>i(e))};return l.find(e=>d(e)&&f(e))??l.find(d)??o(Math.max(i.y,Math.min(s,u-Fr)))}reservedBoxes(t){let{chartRect:n}=t;return this.reservedLevels().map(r=>{let i=e.T(r,t)-Br;return{left:n.x,top:i-Fr,right:n.x+n.width,bottom:i}})}closesOn(e,n){let r=n.length>0?n[n.length-1].time:NaN,i=this.aligned.get(e.id);if(i&&i.main===n&&i.data===e.data&&i.length===n.length&&i.lastTime===r)return i.closes;let a=new Float64Array(n.length),o=(0,t.barTimeUnit)(n);for(let t=0;t<n.length;t++)a[t]=this.store.closeAt(e.id,n[t].time,o)??NaN;return this.aligned.set(e.id,{main:n,data:e.data,length:n.length,lastTime:r,closes:a}),a}anchor(e,t,n){let r=this.closesOn(e,t),i=Math.max(0,n.visibleRange.from),a=Math.min(t.length-1,n.visibleRange.to),o=-1;for(let e=i;e<=a;e++)if(Number.isFinite(r[e])&&r[e]!==0&&t[e].close!==0){o=e;break}if(o<0)return null;let s=n.scaleBaseline||t[i]?.close||t[o].close;return{closes:r,base:o,to:a,mainBase:s,symBase:r[o]}}line(e,t,n){let r=this.anchor(e,t,n);if(!r)return null;let{closes:i,mainBase:a,symBase:o}=r,s=this.mode===`percent`;return{from:r.base,to:r.to,priceAt:e=>{let t=i[e];return Number.isFinite(t)?s?t/o*a:t:null}}}valuesAt(e,n,r){let i=e[r]?.time,a=(0,t.barTimeUnit)(e);return this.getSymbols().map(t=>{let r=i===void 0?void 0:this.store.lastCloseAt(t.id,i,a),o=r&&n?this.anchor(t,e,n)?.symBase:void 0,s=r?.close??null;return{id:t.id,label:t.label,color:t.color,visible:t.visible,close:s,change:s!==null&&o?(s/o-1)*100:null,stale:r?.stale??!1}})}renderSymbol(t,n,r,i){let a=this.line(n,r,i);if(!a)return null;t.strokeStyle=n.color,t.lineWidth=n.lineWidth??1.5,t.lineJoin=`round`,t.beginPath();let o=0,s=null;for(let n=a.from;n<=a.to;n++){let r=a.priceAt(n);if(r===null)continue;let c=e.b(n,i),l=e.T(r,i);o===0?t.moveTo(c,l):t.lineTo(c,l),s={x:c,y:l},o++}return t.stroke(),s}};function Ur(e){if(e.length===0)return[];let t=[],n=e[0].open,r=(e[0].open+e[0].high+e[0].low+e[0].close)/4;for(let i=0;i<e.length;i++){let a=e[i],o=(a.open+a.high+a.low+a.close)/4,s=i===0?a.open:(n+r)/2,c=Math.max(a.high,s,o),l=Math.min(a.low,s,o);t.push({time:a.time,open:s,high:c,low:l,close:o,volume:a.volume}),n=s,r=o}return t}var Wr=1e5,Gr=[1,2,5],Kr=15;function qr(e,t){if(t===0)return e;let n=Gr[t%Gr.length],r=Math.floor(t/Gr.length),i=n*10**r;if(Number.isFinite(i))return Number((e*i).toPrecision(Kr));let[a,o]=e.toExponential().split(`e`);return Number(`${(Number(a)*n).toPrecision(Kr)}e${Number(o)+r}`)}function Jr(e,t,n){return e===t-1?n+Wr:Wr}var Yr=class{reached=null;clear(){this.reached=null}startStep(e,t,n){let r=this.reached;if(!r||r.kind!==e||r.asked!==t||n.length<r.length||n[0].time!==r.first)return 0;let i=n[r.length-1];return i.high>=r.high&&i.low<=r.low?r.step:0}keep(e,t,n,r){let i=r[r.length-1];this.reached=i?{kind:e,asked:t,step:n,first:r[0].time,length:r.length,high:i.high,low:i.low}:null}};function Xr(e,t,n,r,i){let a=i(e?.startStep(t,n,r)??0);return e?.keep(t,n,a.step,r),a}function Zr(e,t,n=0){return $r(e,t,()=>({bars:[],size:1/0,step:0}),n)}function Qr(e,t,n=0){return $r(e,t,()=>({bars:ei(e,t,!1)??[],size:e,step:0}),n)}function $r(e,t,n,r){let i=qr(e,r),a=ei(i,t,!0);if(a)return{bars:a,size:i,step:r};let o=ti(e,e=>t(e,!0),r),s=Number.isFinite(o)?qr(e,o):1/0,c=Number.isFinite(s)?ei(s,t,!0):null;return c?{bars:c,size:s,step:o}:n()}function ei(e,t,n){let r=[];return t(e,n,e=>{r.push(e)})?r:null}function ti(e,t,n){if(!(e>0))return 1/0;let r=n=>{let r=qr(e,n);return r===1/0||t(r)};if(r(n+1))return n+1;if(!t(Number.MAX_VALUE))return 1/0;let i=n+1,a=n+2;for(;!r(a);)i=a,a=n+2*(a-n);for(;a-i>1;){let e=Math.floor((i+a)/2);r(e)?a=e:i=e}return a}var ni=new WeakMap,ri=new WeakMap;function ii(e,t){return ni.set(e,t),e}function ai(e){let t=e[e.length-1];if(!t||!ni.has(t))return e;let n=ri.get(e);if(!n){let t=ni.get(e[0])??e[0].time;n=e.map(e=>(t=ni.get(e)??t,{time:t})),ri.set(e,n)}return n}function oi(e,t,n){if(e.length===0)return[];let r=si(e,t),i=(t,n,r)=>ci(e,t,n,r);return Xr(n,`renko`,r,e,e=>Zr(r,i,e)).bars}function si(e,t){let n=t.useATR&&e.length>2?ui(e,t.atrPeriod??14):t.brickSize;return n>0?n:Math.abs(e[e.length-1].close)/100||1}function ci(e,t,n,r){let i=e.findIndex(e=>Number.isFinite(e.close));if(i<0)return!0;let a=e[0].time,o=Math.round(e[i].close/t)*t,s=0;for(let c=i+1;c<e.length;c++){let{close:i,volume:l}=e[c],u=i-o,d=Math.floor(Math.abs(u)/t);if(!Number.isFinite(i)||!(d>=1))continue;if(n&&s+d>Jr(c,e.length,s))return!1;let f=u>0?1:-1;for(let n=0;n<d;n++){let i=o;o+=f*t,r?.(ii(li(a+s+n,i,o,l/d),e[c].time))}s+=d}return!0}function li(e,t,n,r){return{time:e,open:t,high:Math.max(t,n),low:Math.min(t,n),close:n,volume:r}}function ui(e,t){let n=e.length-1,r=Math.max(1,n-t),i=0;for(let t=r;t<n;t++)i+=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));let a=n>r?i/(n-r):0;if(!(a>0))return 0;let o=10**(Math.floor(Math.log10(a))-1);return Math.round(a/o)*o}function di(e,t=3){if(e.length===0)return[];let n=[],r=0;n.push(ii({time:r++,open:e[0].open,high:Math.max(e[0].open,e[0].close),low:Math.min(e[0].open,e[0].close),close:e[0].close,volume:e[0].volume},e[0].time));for(let i=1;i<e.length;i++){let a=e[i].close,o=n[n.length-1],s=o.close>=o.open,c=Math.min(t,n.length),l=-1/0,u=1/0;for(let e=n.length-c;e<n.length;e++)l=Math.max(l,n[e].high),u=Math.min(u,n[e].low);s&&a>o.close?n.push(ii({time:r++,open:o.close,high:a,low:o.close,close:a,volume:e[i].volume},e[i].time)):!s&&a<o.close||s&&a<u?n.push(ii({time:r++,open:o.close,high:o.close,low:a,close:a,volume:e[i].volume},e[i].time)):!s&&a>l&&n.push(ii({time:r++,open:o.close,high:a,low:o.close,close:a,volume:e[i].volume},e[i].time))}return n}function fi(e,t=4,n=`percent`,r){if(e.length<2)return e.slice();let i=(t,r,i)=>pi(e,t,n,r,i);return Xr(r,`kagi:${n}`,t,e,e=>Qr(t,i,e)).bars}function pi(e,t,n,r,i){let a=e[1].close>=e[0].close?1:-1,o=e[0].close,s=e[0].close,c=e[0].close,l=0;for(let u=1;u<e.length;u++){let d=e[u].close,f=n===`price`?t:t/100*c;if(a===1&&d>o&&(o=d),a===-1&&d<s&&(s=d),a===1?o-d>=f:d-s>=f){if(r&&l+1>Jr(u,e.length,l))return!1;i?.(ii(mi(l,c,a===1?o:s,e[u].volume),e[u].time)),l++,c=a===1?o:s,a=-a,o=d,s=d}}return i?.(ii(mi(l,c,a===1?o:s,0),e[e.length-1].time)),!0}function mi(e,t,n,r){return{time:e,open:t,high:Math.max(t,n),low:Math.min(t,n),close:n,volume:r}}function hi(e,t,n=3,r){return gi(e,t,n,r).columns}function gi(e,t,n=3,r){if(e.length===0||!(t>0))return{columns:[],boxSize:t};let i=(t,r,i)=>_i(e,t,n,r,i),{bars:a,size:o}=Xr(r,`pointAndFigure:${n}`,t,e,e=>Qr(t,i,e));return{columns:a,boxSize:o}}function _i(e,t,n,r,i){let a=1,o=0,s=e[0].close,c=Math.round(s/t)*t;if(vi(s,c))return!1;let l=c,u=c,d=e[0].volume,f=t*n;for(let n=1;n<e.length;n++){let s=e[n].close,c=Math.round(s/t)*t;if(vi(s,c))return!1;let p=!1;if(a===1?c>l?l=c:p=l-c>=f:c<u?u=c:p=c-u>=f,!p){d+=e[n].volume;continue}if(r&&o+1>Jr(n,e.length,o))return!1;i?.(ii(yi(o,a===1,u,l,d),e[n].time)),d=e[n].volume,o++,a===1?(u=c,l-=t):(l=c,u+=t),a=-a}return i?.(ii(yi(o,a===1,u,l,d),e[e.length-1].time)),!0}function vi(e,t){return Number.isFinite(e)&&!Number.isFinite(t)}function yi(e,t,n,r,i){return{time:e,open:t?n:r,high:r,low:n,close:t?r:n,volume:i}}var bi=15,xi=`rangeBars`,Si=3,Ci=4,wi=64,Ti=2;function Ei(e){let t=0;for(let n of e){let e=Math.abs(n.high),r=Math.abs(n.low);e>t&&e!==1/0&&(t=e),r>t&&r!==1/0&&(t=r)}return t}function Di(e,t){let n=Math.max(e,t),r=Math.floor(Math.log10(n))+1,i=Number.isFinite(n)?bi-r:0,a=10**-i;if(i<=0)return{clean:e=>e,unit:a,half:0};let o=10**i;return{clean:e=>Math.round(e*o)/o,unit:a,half:a/2}}function Oi(e,t){let n=-1/0,r=1/0;for(let i of[t,e.open,e.high,e.low,e.close])Number.isFinite(i)&&(n=Math.max(n,i),r=Math.min(r,i));return n>r?n-r:0}function ki(e){let t=0,n=e[0].open;for(let r=0;r<e.length-1;r++)t+=Oi(e[r],n),n=e[r].close;return{distance:t,bars:e.length-1,lastSpan:Oi(e[e.length-1],n)}}function Ai(e,t,n){if(t<Ti*n)return!1;let r=t+n,i=(e.distance-e.bars*n)/r-e.bars,a=(e.lastSpan-n)/r-1;return Math.max(i,a)>Wr+1}function ji(e){let t=new Float64Array(e.length*2);return t.set(e),t}function Mi(e,t,n,r){let i=r/(n-t);for(let r=t;r<n;r++)e[r*Ci+2]+=i}function Ni(e,t,n,r){let i=Array(t);for(let a=0;a<t;a++){let t=e[a*Ci],o=e[a*Ci+1],s=t>o;i[a]=ii({time:r+a,open:n,high:s?t:o,low:s?o:t,close:t,volume:e[a*Ci+2]},e[a*Ci+3]),n=t}return i}function Pi(e,t,n,r){let{clean:i,unit:a,half:o}=n,s=0,c=e[0].open,l=c,u=c,d=c,f=0,p=i(c+t),m=i(c-t);for(let n=0;n<e.length;n++){let h=Jr(n,e.length,s),g=e[n],_=g.close>=g.open,v=g.volume/Si;for(let e=0;e<=Si;e++){let n=e===0?g.open:e===1?_?g.low:g.high:e===2?_?g.high:g.low:g.close;if(!Number.isFinite(n))continue;d=n;let y=s;for(;;){let e=n>l&&n>=p-o&&p>u;if(!e&&!(n<u&&n<=m+o&&m<l))break;let d=e?p:m;if(e?d<l-a:d>u+a)return{cells:r,count:s,forming:null};let _=s*Ci;if(_===r.length&&(r=ji(r)),r[_]=d,r[_+1]=e?u:l,r[_+2]=f,r[_+3]=g.time,++s>h)return{cells:r,count:s,forming:null};c=l=u=d,p=i(d+t),m=i(d-t),f=0}n>l&&(l=n,m=i(n-t)),n<u&&(u=n,p=i(n+t));let b=e===0?0:v;s===y?f+=b:Mi(r,y,s,b)}}let h={time:e[0].time+s,open:c,high:l,low:u,close:d,volume:f};return{cells:r,count:s,forming:ii(h,e[e.length-1].time)}}function Fi(e,t,n){if(e.length===0||!(t.rangeSize>0))return[];let r=Ei(e),i=new Float64Array(Ci*Math.max(wi,Math.min(e.length,Wr))),a=null,o=n?.startStep(xi,t.rangeSize,e)??0;for(let s=o;;s++){let c=qr(t.rangeSize,s),l=Di(r,c);if(s>o&&(a??=ki(e),Ai(a,c,l.unit)))continue;let u=Pi(e,c<l.half?1/0:c,l,i);if(i=u.cells,!u.forming)continue;let d=Ni(i,u.count,e[0].open,e[0].time),{forming:f}=u;return t.includeForming&&(d.length===0||f.high-f.low>l.half)&&d.push(f),n?.keep(xi,t.rangeSize,s,e),d}}function Ii(e){return e.barWidth+e.barSpacing<1}function Li(e,t,n){return e>1.5*(Math.abs(n-t)+1)}var Ri=3,zi=class{started=!1;piece=0;lastX=NaN;lastY=NaN;col=NaN;lo=0;hi=0;width;constructor(e,t,n,r,i=[]){this.ctx=e,this.dense=r,this.dash=i,this.width=Number.isFinite(n)&&n>0?n:1,e.beginPath(),r?e.fillStyle=t:(e.strokeStyle=t,e.lineWidth=this.width,e.lineJoin=`round`)}add(e,t){!Number.isFinite(e)||!Number.isFinite(t)||(this.dense?this.addDense(e,t):this.started?this.ctx.lineTo(e,t):this.ctx.moveTo(e,t),this.started=!0,this.piece++,this.lastX=e,this.lastY=t)}gap(){this.endPiece(),this.flush(),this.started=!1,this.lastY=NaN}segment(e,t,n,r){(!this.started||e!==this.lastX||t!==this.lastY)&&(this.gap(),this.add(e,t)),this.add(n,r)}finish(){this.endPiece(),this.flush(),this.dense?this.ctx.fill():this.dash.length>0?(this.ctx.setLineDash([...this.dash]),this.ctx.stroke(),this.ctx.setLineDash([])):this.ctx.stroke()}endPiece(){if(!this.dense&&this.piece===1){let e=Math.max(this.width,Ri);this.ctx.moveTo(this.lastX-e,this.lastY),this.ctx.lineTo(this.lastX+e,this.lastY)}this.piece=0}addDense(e,t){let n=Math.floor(e);n!==this.col&&(this.flush(),this.col=n,this.lo=this.hi=Number.isNaN(this.lastY)?t:this.lastY),t<this.lo&&(this.lo=t),t>this.hi&&(this.hi=t)}flush(){if(Number.isNaN(this.col))return;let e=this.width/2,t=Math.max(1,this.width);this.ctx.rect(this.col+.5-t/2,this.lo-e,t,this.hi-this.lo+2*e),this.col=NaN}};function Bi(e,t,n,r,i,a=t.length){e.beginPath(),e.fillStyle=i;let o=NaN,s=0,c=0,l=NaN,u=NaN,d=()=>{Number.isNaN(o)||e.rect(o,s,1,c-s)};for(let e=0;e<a;e++){let i=Math.floor(t[e]),a=Math.min(n[e],r[e]),f=Math.max(n[e],r[e]);i!==o&&(d(),o=i,s=Number.isNaN(l)?a:Math.min(a,l),c=Number.isNaN(u)?f:Math.max(f,u)),a<s&&(s=a),f>c&&(c=f),l=a,u=f}d(),e.fill()}var Vi=.1;function Hi(e){return e.plots?e.plots.map(e=>e.key):null}function Ui(e,t){return e.tone?e.tone===`sign`?(t[e.key]??0)>=0:t[e.tone.field]===1:!0}function Wi(e,t){return t.plots?.[e.key]?.visible!==!1}var Gi=[6,4];function Ki(e,n,r){let i=e.plots?.[n];return{visible:i?.visible!==!1,dash:(0,t.lineDash)(i?.lineStyle??`solid`,Gi,r)}}function qi(e,t,n){let r=t.colors[e.color]??t.colors[0];return!e.tone||e.downColor===void 0||!n||Ui(e,n)?r:t.colors[e.downColor]??r}function Ji(e,t,n,r){let{lo:i,hi:a}=Xi(e,t,n,r.keys),o=r.scale,s=o?.min,c=o?.max;if(i===1/0){if(s===void 0&&c===void 0)return null;i=s??0,a=c??i+1}else{let e=a-i||Math.abs(a)||1;i-=e*Vi,a+=e*Vi}for(let e of r.levels??[])e<i&&(i=e),e>a&&(a=e);return(r.zero||o?.zero)&&(i>0&&(i=0),a<0&&(a=0)),s!==void 0&&(i=s),c!==void 0&&(a=c),a>i||(a=i+1),{min:i,max:a}}function Yi(e,t,n,r){let{lo:i,hi:a}=Xi(e,t,n,r.keys),o=e=>e!==void 0&&e>0,s=o(r.scale?.min)?r.scale?.min:void 0,c=o(r.scale?.max)?r.scale?.max:void 0;if(i===1/0){if(s===void 0||c===void 0)return null;i=s,a=c}else{if(!(i>0))return!1;let e=Math.exp((Math.log(a/i)||Math.LN2/4)*Vi);i/=e,a*=e}for(let e of r.levels??[])e>0&&(e<i&&(i=e),e>a&&(a=e));return s!==void 0&&(i=s),c!==void 0&&(a=c),a>i?{min:i,max:a}:null}function Xi(e,t,n,r){let i=1/0,a=-1/0,o=e=>{e===void 0||!Number.isFinite(e)||(e<i&&(i=e),e>a&&(a=e))},s=e=>{if(e){if(r){for(let t=0;t<r.length;t++)o(e[r[t]]);return}for(let t in e)o(e[t])}},c=e?.series;if(c){let e=Math.min(n,c.length-1);for(let n=Math.max(0,t);n<=e;n++)s(c[n])}else if(e){let r=0;for(let i of e.values.values()){if(r>n)break;r>=t&&s(i),r++}}return{lo:i,hi:a}}function Zi(e){return!!e?.some(e=>e.kind===`histogram`)}function Qi(n,r,i,a,o,s=[]){let c=r.series;if(!c)return;let l=Math.max(0,i.visibleRange.from),u=Math.min(i.visibleRange.to,c.length-1);if(u<l)return;let d=e.E(i);for(let e of s){let r=(0,t.withAlpha)(a.colors[e.color]??a.colors[0],e.opacity??$i);ea(n,c,e.between,l,u,i,d,r)}for(let e=0;e<o.length;e++){let r=o[e];if(!Wi(r,a))continue;let s=(e>0?a.lineWidths[e]:void 0)??r.width??a.lineWidths[0]??1.5,f=(0,t.lineDash)(a.plots?.[r.key]?.lineStyle??r.lineStyle??`solid`,Gi,s),p=r.kind??`line`,m=r.breakOn,h=m===void 0?null:(e,t)=>kt(c,e,t,m),g=n.globalAlpha;r.opacity!==void 0&&(n.globalAlpha=g*r.opacity);let _=r.tone&&r.downColor!==void 0?[!0,!1]:[null];try{for(let e of _){let t=a.colors[r.color]??a.colors[0],o=e===!1?a.colors[r.downColor]??t:t,m=t=>e===null||Ui(r,t)===e;p===`histogram`?aa(n,c,r.key,l,u,i,d,o,m):p===`dots`?ia(n,c,r.key,l,u,i,d,o,m):ra(n,c,r.key,l,u,i,d,o,s,p===`step`,e===null?null:m,f,h)}}finally{n.globalAlpha=g}}}var $i=.1;function ea(t,n,r,i,a,o,s,c){let l=a-i+1,u=new Float64Array(l),d=new Float64Array(l),f=new Float64Array(l),p=Ii(o),m=0,h=()=>{m>=2&&(p?Bi(t,u,d,f,c,m):ta(t,u,d,f,c,m)),m=0};for(let t=i;t<=a;t++){let i=na(n[t],r[0]),a=na(n[t],r[1]);if(i===void 0||a===void 0){h();continue}u[m]=e.b(t,o),d[m]=s(i),f[m]=s(a),m++}h()}function ta(e,t,n,r,i,a){e.beginPath(),e.moveTo(t[0],n[0]);for(let r=1;r<a;r++)e.lineTo(t[r],n[r]);for(let n=a-1;n>=0;n--)e.lineTo(t[n],r[n]);e.closePath(),e.fillStyle=i,e.fill()}function na(e,t){let n=e?.[t];return n!==void 0&&Number.isFinite(n)?n:void 0}function ra(t,n,r,i,a,o,s,c,l,u,d,f=[],p=null){let m=new zi(t,c,l,Ii(o),f),h=0,g=0,_=!1,v=-1;for(let t=i;t<=a;t++){let i=n[t],a=na(i,r);if(a===void 0){_=!1,m.gap();continue}_&&p?.(v,t)&&(_=!1,m.gap()),v=t;let c=e.b(t,o),l=s(a);d?_&&d(i)&&(u?(m.segment(h,g,c,g),m.add(c,l)):m.segment(h,g,c,l)):(_&&u&&m.add(c,g),m.add(c,l)),h=c,g=l,_=!0}m.finish()}function ia(t,n,r,i,a,o,s,c,l){let u=Math.max(1.5,o.barWidth*.15),d=Ii(o),f=NaN;t.beginPath(),t.fillStyle=c;for(let c=i;c<=a;c++){let i=n[c],a=na(i,r);if(a===void 0||!l(i))continue;let p=e.b(c,o);if(d){let e=Math.floor(p);if(e===f)continue;f=e}let m=s(a);t.moveTo(p+u,m),t.arc(p,m,u,0,Math.PI*2)}t.fill()}function aa(t,n,r,i,a,o,s,c,l){let u=s(0);if(t.beginPath(),t.fillStyle=c,Ii(o)){let c=NaN,d=0,f=()=>{if(Number.isNaN(c))return;let e=s(d);t.rect(c,Math.min(e,u),1,Math.max(1,Math.abs(e-u)))};for(let t=i;t<=a;t++){let i=n[t],a=na(i,r);if(a===void 0||!l(i))continue;let s=Math.floor(e.b(t,o));s===c?Math.abs(a)>Math.abs(d)&&(d=a):(f(),c=s,d=a)}f(),t.fill();return}let d=Math.max(1,o.barWidth);for(let c=i;c<=a;c++){let i=n[c],a=na(i,r);if(a===void 0||!l(i))continue;let f=e.b(c,o),p=s(a);t.rect(f-d/2,Math.min(p,u),d,Math.max(1,Math.abs(p-u)))}t.fill()}var I=class{canResume(e,t,n){let r=t.series;if(!r||n<=0||n>r.length||r.length>e.length)return!1;for(let i=n;i<r.length;i++)if(r[i]&&!t.values.has(e[i].time))return!1;return!0}writePoint(e,t,n,r){e.series[n]=r,r?e.values.set(t[n].time,r):e.values.delete(t[n].time)}render(e,t,n,r){this.descriptor.plots&&Qi(e,t,n,r,this.descriptor.plots,this.descriptor.fills)}drawLine(e,t,n,r,i){if(t.length<2||i?.visible===!1)return;let a=new zi(e,n,r,Li(t.length,t[0].x,t[t.length-1].x),i?.dash);for(let e of t)a.add(e.x,e.y);a.finish()}drawBand(e,t,n,r){if(!(t.length<2||n.length<2)){if(t.length===n.length&&Li(t.length,t[0].x,t[t.length-1].x)){Bi(e,t.map(e=>e.x),t.map(e=>e.y),n.map(e=>e.y),r);return}e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);for(let t=n.length-1;t>=0;t--)e.lineTo(n[t].x,n[t].y);e.closePath(),e.fillStyle=r,e.fill()}}drawHistogram(e,t,n){let r=n/2;for(let i of t){e.fillStyle=i.color;let t=Math.min(i.y,i.baseY),a=Math.abs(i.y-i.baseY);e.fillRect(i.x-r,t,n,Math.max(a,1))}}valuesToPoints(t,n,r,i){let a=[],{from:o,to:s}=i.visibleRange;for(let c=o;c<=s&&c<r.length;c++){let o=t.values.get(r[c].time);o&&o[n]!==void 0&&a.push({x:e.b(c,i),y:e.T(o[n],i)})}return a}};function oa(e){return e.config.visible!==!1&&!e.offInterval&&!e.offChartType}function sa(e){let t=Hi(e.plugin.descriptor),n=e.style.plots;return t&&n?t.filter(e=>n[e]?.visible!==!1):t}function ca(e,t){return e.plugin.descriptor.placement!==`overlay`||e.config.pane?!1:e.config.scale===`left`==(t===`left`)}function la(e){let t=e.output?.series,n=e.plugin.descriptor.plots;if(!t||!n||!oa(e))return[];let r=t[t.length-1];if(!r)return[];let i=[];for(let t of n){if(!Wi(t,e.style))continue;let n=r[t.key];n!==void 0&&Number.isFinite(n)&&i.push({value:n,color:qi(t,e.style,r)})}return i}function ua(e,t){let n=[];for(let r of e)ca(r,t)&&n.push(...la(r));return n}function da(e,t,n,r){let i=null;for(let a of e){if(!oa(a))continue;let e=a.plugin.descriptor,o={keys:sa(a),scale:e.scale,levels:a.config.levels??e.levels,zero:Zi(e.plots)},s=r?Yi(a.output,t,n,o):Ji(a.output,t,n,o);if(s===!1)return null;s&&(i=i?{min:Math.min(i.min,s.min),max:Math.max(i.max,s.max)}:s)}return i}function fa(e,t){let n=[];for(let r of e){if(!oa(r))continue;let e=r.output?.series?.[t];if(!e)continue;let i=sa(r)??Object.keys(e);for(let t of i){let r=e[t];typeof r==`number`&&Number.isFinite(r)&&n.push(r)}}return n}function pa(e,t,n){if(n){for(let r=0;r<n.length;r++){let i=t[n[r]];i!==void 0&&isFinite(i)&&(i<e.min&&(e.min=i),i>e.max&&(e.max=i))}return}for(let n in t){let r=t[n];r!==void 0&&isFinite(r)&&(r<e.min&&(e.min=r),r>e.max&&(e.max=r))}}function ma(e,t,n,r){let i=t.output?.series;if(!i)return;let a=sa(t),o=Math.min(r,i.length-1),s=r>=i.length-1?t.output?.meta?.ahead:void 0,c=Array.isArray(s)?s:[];for(let t=Math.max(0,n);t<=o+c.length;t++){let n=t<=o?i[t]:c[t-o-1];n&&pa(e,n,a)}}function ha(e,t,n,r){let i={min:1/0,max:-1/0};for(let a of e)!a.output||!oa(a)||!ca(a,r)||ma(i,a,t,n);return i.min===1/0?null:i}function ga(e,t,n,r){let i=new Set;for(let a of e)a.config.instanceId!==r&&(n===null?t===`overlay`&&a.plugin.descriptor.placement===`overlay`&&!a.config.pane:a.config.instanceId===n||a.config.pane===n)&&i.add(a.style.colors[0]);return i}function _a(e,n,r,i,a){let o=ga(e,r,i,a);for(let t of e)t.config.id===n&&t.config.instanceId!==a&&o.add(t.style.colors[0]);let s=t.TC_SERIES_COLORS.findIndex(e=>!o.has(e));return s>=0?s:o.size%t.TC_SERIES_COLORS.length}function va(e){let t=e.inputs;if(!t)return null;for(let e in t)if(t[e]?.source)return e;return null}function ya(e,n){let r=va(e);if(!r)return{kind:`bars`};let i=n[r],a=(0,t.parseIndicatorSource)(i);return a?{kind:`line`,...a}:(0,t.isPriceSource)(i)&&i!==`close`?{kind:`price`,source:i}:{kind:`bars`}}function ba(e,n,r=null,i=0){let a=r&&i>0&&i<=r.length?r:[],o=a===r?i:0;a.length=e.length;for(let r=o;r<e.length;r++){let i=e[r];a[r]={...i,close:(0,t.sourcePrice)(i,n)}}return a}function xa(e,t,n){if(!t)return null;let r=-1;for(let i=0;i<e.length&&i<t.length;i++){let e=t[i]?.[n];if(e!==void 0&&Number.isFinite(e)){r=i;break}}if(r<0)return null;let i=Array(e.length-r),a=t[r][n];for(let o=r;o<e.length;o++){let s=t[o]?.[n];s!==void 0&&Number.isFinite(s)&&(a=s);let c=e[o];i[o-r]={time:c.time,open:a,high:a,low:a,close:a,volume:c.volume}}return{bars:i,start:r}}function Sa(e,t,n){if(t===0||!e.series)return e;let r=Array(n).fill(null);for(let i=0;i<e.series.length&&t+i<n;i++)r[t+i]=e.series[i];return{...e,series:r}}function Ca(e){return{values:new Map,series:Array(e).fill(null)}}var wa=[`ticks`,`seconds`,`minutes`,`hours`,`days`,`weeks`,`months`],Ta={ticks:1e6,seconds:59,minutes:59,hours:24,days:366,weeks:52,months:12},Ea={s:`seconds`,m:`minutes`,h:`hours`,d:`days`,w:`weeks`,M:`months`};function Da(e){let n=(0,t.tickBarCount)(e);if(n!==null)return{unit:`ticks`,count:n};let r=(0,t.parseTimeframe)(e);return r?{unit:Ea[r.unit],count:r.count}:null}function Oa(e,t){if(!e||!t)return!0;let n=Da(t);if(!n)return!0;let r=e[n.unit];return r===void 0?!0:r===!1?!1:n.count>=r[0]&&(n.count<=r[1]||r[1]>=Ta[n.unit])}function ka(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let t=e,n={};for(let e of wa){let r=t[e];if(r===!1){n[e]=!1;continue}if(!Array.isArray(r)||r.length!==2||!r.every(e=>typeof e==`number`&&Number.isFinite(e)))continue;let i=Ta[e],[a,o]=r.map(e=>Math.min(i,Math.max(1,Math.round(e)))).sort((e,t)=>e-t);(a>1||o<i)&&(n[e]=[a,o])}return Object.keys(n).length>0?n:null}function Aa(e){return[...t.TC_SERIES_COLORS.slice(e),...t.TC_SERIES_COLORS.slice(0,e)]}function ja(e){let n=t.TC_SERIES_COLORS.length;if(e.length!==n)return!1;let r=t.TC_SERIES_COLORS.indexOf(e[0]);return r>=0&&e.every((e,i)=>e===t.TC_SERIES_COLORS[(r+i)%n])}function Ma(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,{...t}]))}function Na(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t===!1?!1:[t[0],t[1]]]))}var Pa=new WeakSet,L=class e extends Map{keyBuf=[];valBuf=[];folded=!1;constructor(){super()}static fromAscending(t,n){let r=new e;for(let e=1;e<t.length;e++)if(!(t[e]>t[e-1])){for(let e=0;e<t.length;e++)r.set(t[e],n[e]);return r}return r.keyBuf=t,r.valBuf=n,r}set(e,t){if(this.folded)return super.set(e,t);let n=this.keyBuf,r=n.length;if(r===0||e>n[r-1])return n.push(e),this.valBuf.push(t),this;let i=this.indexOf(e);return i>=0?(this.valBuf[i]=t,this):(this.fold(),super.set(e,t))}get(e){if(this.folded)return super.get(e);let t=this.indexOf(e);return t>=0?this.valBuf[t]:void 0}has(e){return this.folded?super.has(e):this.indexOf(e)>=0}delete(e){if(this.folded)return super.delete(e);let t=this.indexOf(e);return t<0?!1:(this.keyBuf.splice(t,1),this.valBuf.splice(t,1),!0)}clear(){super.clear(),this.keyBuf=[],this.valBuf=[],this.folded=!1}get size(){return this.folded?super.size:this.keyBuf.length}forEach(e,t){this.fold(),super.forEach(e,t)}entries(){return this.fold(),super.entries()}keys(){return this.fold(),super.keys()}values(){return this.fold(),super.values()}[Symbol.iterator](){return this.fold(),super[Symbol.iterator]()}indexOf(e){let t=this.keyBuf,n=0,r=t.length-1;for(;n<=r;){let i=n+r>>1,a=t[i];if(a===e)return i;a<e?n=i+1:r=i-1}return-1}fold(){if(this.folded)return;this.folded=!0;let e=this.keyBuf,t=this.valBuf;for(let n=0;n<e.length;n++)super.set(e[n],t[n]);this.keyBuf=[],this.valBuf=[]}};function R(e,t){let n=new L;for(let r=0;r<t.length;r++){let i=t[r];i&&n.set(e[r].time,i)}return{values:n,series:t}}function Fa(e){return e.map(e=>e.close)}function Ia(e,t){let n=Array(e.length).fill(void 0),r=0,i=0;for(let a=0;a<e.length;a++){let o=e[a];if(o===void 0){r=0,i=0;continue}r+=o,i++,i>t&&(r-=e[a-t]),i>=t&&(n[a]=r/t)}return n}function La(e,t,n){let r=Array(e.length).fill(void 0),i=0,a=0,o;for(let s=0;s<e.length;s++){let c=e[s];if(c!==void 0){if(o===void 0){i+=c,a++,a===t&&(r[s]=o=i/t);continue}o+=n*(c-o),r[s]=o}}return r}function z(e,t){return La(e,t,2/(t+1))}function Ra(e,t){let n=Array(e.length).fill(void 0),r=t*(t+1)/2;for(let i=t-1;i<e.length;i++){let a=0,o=!0;for(let n=0;n<t;n++){let r=e[i-t+1+n];if(r===void 0){o=!1;break}a+=r*(n+1)}o&&(n[i]=a/r)}return n}function za(e,t){return La(e,t,1/t)}function Ba(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=0,o=!0;for(let n=r-t+1;n<=r;n++){let t=e[n];if(t===void 0){o=!1;break}i+=t,a+=t*t}if(!o)continue;let s=i/t;n[r]=Math.sqrt(Math.max(0,a/t-s*s))}return n}function Va(e){return e.map((t,n)=>{if(n===0)return t.high-t.low;let r=e[n-1].close;return Math.max(t.high-t.low,Math.abs(t.high-r),Math.abs(t.low-r))})}function Ha(e,t,n){if(t<n-1)return;let r=-1/0;for(let i=t-n+1;i<=t;i++){let t=e[i];if(t===void 0)return;t>r&&(r=t)}return r}function Ua(e,t,n){if(t<n-1)return;let r=1/0;for(let i=t-n+1;i<=t;i++){let t=e[i];if(t===void 0)return;t<r&&(r=t)}return r}function Wa(e,t=`value`){return e.map(e=>e!==void 0&&Number.isFinite(e)?{[t]:e}:null)}function Ga(e,t,n){if(t<n-1||t>=e.length)return;let r=0,i=0;for(let a=t-n+1;a<=t;a++){let t=e[a].close;r+=t,i+=t*t}let a=r/n;return{mean:a,sd:Math.sqrt(Math.max(0,i/n-a*a))}}function Ka(e,t,n){if(t<n-1)return;let r=-1/0;for(let i=t-n+1;i<=t;i++)e[i].high>r&&(r=e[i].high);return r}function qa(e,t,n){if(t<n-1)return;let r=1/0;for(let i=t-n+1;i<=t;i++)e[i].low<r&&(r=e[i].low);return r}function Ja(e,t,n){if(t<n-1)return;let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i].close;return r/n}function Ya(e,t,n){if(n<2||t<n-1)return;let r=n,i=(r-1)/2,a=0;for(let n=0;n<r;n++)a+=e[t-r+1+n].close;a/=r;let o=0,s=0,c=0;for(let n=0;n<r;n++){let l=n-i,u=e[t-r+1+n].close-a;o+=l*u,s+=l*l,c+=u*u}let l=o/s,u=a-l*i,d=0;for(let n=0;n<r;n++){let i=e[t-r+1+n].close-(u+l*n);d+=i*i}return{slope:l,end:u+l*(r-1),stdErr:r>2?Math.sqrt(d/(r-2)):0,r:c===0?0:o/Math.sqrt(s*c)}}var Xa=new WeakMap;function Za(e){let t=Xa.get(e);return t||Xa.set(e,t=Array.from(e)),t}var B=class extends I{times=new WeakMap;workerState(){}adoptWorkerState(e,t,n){this.times.set(e,Za(n))}lookback(e){return 0}revisesBefore(e){return this.lookback(this.read(e))}calculate(e,t){let n=this.read(t),r=Array(e.length);for(let t=0;t<e.length;t++)r[t]=this.pointAt(e,t,n);let i=R(e,r);return this.times.set(i,e.map(e=>e.time)),i}update(e,t,n,r){let i=this.times.get(n);if(!i||!this.canResume(e,n,r))return null;for(let t=r;t<i.length&&t<e.length;t++)if(i[t]!==e[t].time)return null;let a=this.read(t);for(let t=Math.max(0,r-this.lookback(a));t<e.length;t++)this.writePoint(n,e,t,this.pointAt(e,t,a));i.length=e.length;for(let t=r;t<e.length;t++)i[t]=e[t].time;return n}},Qa=new Set([`compareSymbol`,`compareSymbolPane`,`spread`,`correlation`,`correlationlog`]),$a=e=>typeof e.params.symbol==`string`?e.params.symbol.trim():``,eo=class extends B{descriptor={id:`compareSymbol`,name:`Compare Symbol`,placement:`overlay`,defaultConfig:{symbol:``},shortName:`Compare`,plots:[{key:`value`,title:`Close`,color:0}],readsExchangeTimeZone:!1};constructor(e){super(),this.store=e}read(e){return{symbol:$a(e)}}pointAt(e,n,{symbol:r}){if(!r)return null;let i=this.store.closeAt(r,e[n].time,(0,t.barTimeUnit)(e));return i===void 0?null:{value:i}}},to=class extends eo{descriptor={id:`compareSymbolPane`,name:`Compare Symbol (Pane)`,placement:`panel`,defaultConfig:{symbol:``},shortName:`Compare`,plots:[{key:`value`,title:`Close`,color:0}],readsExchangeTimeZone:!1}},no=class extends B{descriptor={id:`spread`,name:`Spread / Ratio`,placement:`panel`,defaultConfig:{symbol:``,mode:`spread`},shortName:`Spread`,plots:[{key:`value`,title:`Spread`,color:0}],inputs:{mode:{options:[`spread`,`ratio`]}},readsExchangeTimeZone:!1};constructor(e){super(),this.store=e}read(e){return{symbol:$a(e),ratio:e.params.mode===`ratio`}}pointAt(e,n,{symbol:r,ratio:i}){if(!r)return null;let a=this.store.closeAt(r,e[n].time,(0,t.barTimeUnit)(e));return a===void 0?null:i?a===0?null:{value:e[n].close/a}:{value:e[n].close-a}}},ro=e=>{let t=Math.round(Number(e.params.length??20));return{symbol:$a(e),length:Number.isFinite(t)?Math.max(2,t):20}};function io(e,t){if(e.every(t=>t===e[0])||t.every(e=>e===t[0]))return null;let n=e.length,r=0,i=0;for(let a=0;a<n;a++)r+=e[a],i+=t[a];r/=n,i/=n;let a=0,o=0,s=0;for(let c=0;c<n;c++){let n=e[c]-r,l=t[c]-i;a+=n*l,o+=n*n,s+=l*l}return o>0&&s>0?Math.max(-1,Math.min(1,a/Math.sqrt(o*s))):null}var ao={placement:`panel`,defaultConfig:{symbol:``,length:20},inputs:{length:{kind:`int`,min:2}},plots:[{key:`value`,title:`Correlation`,color:0}],scale:{min:-1,max:1},levels:[0],readsExchangeTimeZone:!1},oo=class extends B{descriptor={...ao,id:`correlation`,name:`Correlation Coefficient`,shortName:`Correlation`};constructor(e){super(),this.store=e}read(e){return ro(e)}pointAt(e,n,{symbol:r,length:i}){if(!r||n<i-1)return null;let a=[],o=[];for(let s=n-i+1;s<=n;s++){let n=this.store.closeAt(r,e[s].time,(0,t.barTimeUnit)(e));if(n===void 0)return null;a.push(e[s].close),o.push(n)}let s=io(a,o);return s===null?null:{value:s}}},so=class extends B{descriptor={...ao,id:`correlationlog`,name:`Correlation Log`,shortName:`Correlation Log`};constructor(e){super(),this.store=e}read(e){return ro(e)}pointAt(e,n,{symbol:r,length:i}){if(!r||n<i)return null;let a=[],o=[],s=this.store.closeAt(r,e[n-i].time,(0,t.barTimeUnit)(e));for(let c=n-i+1;c<=n;c++){let n=this.store.closeAt(r,e[c].time,(0,t.barTimeUnit)(e)),i=e[c-1].close,l=e[c].close;if(n===void 0||s===void 0||!(i>0&&l>0&&n>0&&s>0))return null;a.push(Math.log(l/i)),o.push(Math.log(n/s)),s=n}let c=io(a,o);return c===null?null:{value:c}}};function co(e){let t=e.length,n={time:new Float64Array(t),open:new Float64Array(t),high:new Float64Array(t),low:new Float64Array(t),close:new Float64Array(t),volume:new Float64Array(t)};for(let r=0;r<t;r++){let t=e[r];n.time[r]=t.time,n.open[r]=t.open,n.high[r]=t.high,n.low[r]=t.low,n.close[r]=t.close,n.volume[r]=t.volume}return n}function lo(e){let{time:t,open:n,high:r,low:i,close:a,volume:o}=e,s=Array(t.length);for(let e=0;e<t.length;e++)s[e]={time:t[e],open:n[e],high:r[e],low:i[e],close:a[e],volume:o[e]};return s}function uo(e){let{time:t,open:n,high:r,low:i,close:a,volume:o}=e;return[t,n,r,i,a,o].map(e=>e.buffer)}function fo(e){let t=new Set;for(let n of e)if(n)for(let e in n)t.add(e);return[...t]}function po(e,t){if(e===t)return!0;let n=Object.keys(e);return n.length===Object.keys(t).length?n.every(n=>Object.is(e[n],t[n])):!1}function mo(e,t,n){if(t.length>n.length)return!1;let r=0;for(let i=0;i<t.length;i++){let a=t[i];if(!a)continue;r++;let o=e.values.get(n[i]);if(!o||!po(o,a))return!1}return r===e.values.size}function ho(e,t){let n=e.meta?{meta:e.meta}:{},r=e.series;if(!r)return{present:null,keys:[],columns:[],nans:[],values:new Map(e.values),...n};let i=fo(r),a=new Uint8Array(r.length),o=i.map(()=>new Float64Array(r.length).fill(NaN)),s=i.map(()=>null);for(let e=0;e<r.length;e++){let t=r[e];if(t){a[e]=1;for(let n=0;n<i.length;n++){let a=t[i[n]];a!==void 0&&(o[n][e]=a,Number.isNaN(a)&&((s[n]??=new Uint8Array(r.length))[e]=1))}}}return{present:a,keys:i,columns:o,nans:s,values:mo(e,r,t)?null:new Map(e.values),...n}}function go(e,t){let n={};for(let r=0;r<e.keys.length;r++){let i=e.columns[r][t];(!Number.isNaN(i)||e.nans[r]?.[t]===1)&&(n[e.keys[r]]=i)}return n}function _o(e,t){let[n,r,i,a]=e,[o,s,c,l]=t;switch(e.length){case 1:return n===`value`?e=>({value:o[e]}):e=>({[n]:o[e]});case 2:return e=>({[n]:o[e],[r]:s[e]});case 3:return e=>({[n]:o[e],[r]:s[e],[i]:c[e]});case 4:return e=>({[n]:o[e],[r]:s[e],[i]:c[e],[a]:l[e]});default:return null}}function vo(e,t){for(let n=0;n<e.length;n++)if(Number.isNaN(e[n][t]))return!1;return!0}var yo=class{next=0;series;full;keys=[];points=[];constructor(e,t){this.columns=e,this.time=t,this.series=Array(e.present?.length??0),this.full=_o(e.keys,e.columns)}step(e){let t=this.columns.present;if(!t)return!0;let n=Math.min(t.length,this.next+e),r=this.columns.values===null;for(let e=this.next;e<n;e++){if(t[e]===0){this.series[e]=null;continue}let n=this.full&&vo(this.columns.columns,e)?this.full(e):go(this.columns,e);this.series[e]=n,r&&(this.keys.push(this.time[e]),this.points.push(n))}return this.next=n,n===t.length}output(){let{columns:e}=this,t=e.meta?{meta:e.meta}:{};return e.present?{values:e.values??L.fromAscending(this.keys,this.points),series:this.series,...t}:{values:e.values??new Map,...t}}};function bo(e,t){let n=new yo(e,t);return n.step(1/0),n.output()}function xo(e){let t=e;return typeof t.workerState==`function`&&typeof t.adoptWorkerState==`function`}function So(e){return!!e&&typeof e==`object`&&e.tcPacked===`numbers`}function Co({values:e,missing:t}){let n=Array.from(e);if(t)for(let e=0;e<n.length;e++)t[e]===1&&(n[e]=void 0);return n}function wo(e){if(So(e))return Co(e);if(Array.isArray(e))return e.map(wo);if(!e||typeof e!=`object`)return e;let t={};for(let[n,r]of Object.entries(e))t[n]=wo(r);return t}var To=5e4;function Eo(e){let t=co(e);return{data:e,columns:t,times:t.time.slice()}}function Do(e,t,n,r,i,a){let o=0,s=e=>a(o,e),c=e.submit({indicatorId:t.descriptor.id,config:n,...i.kind===`price`?{source:i.source}:{},bars:r.columns,times:r.times},s);return c===null?null:(o=c,{requestId:o,data:r.data,times:r.times,from:1/0})}function Oo(e){let{data:t,times:n}=e,r=Math.min(e.from,n.length);return r===0||t.length<r?!1:t[0].time===n[0]&&t[r-1].time===n[r-1]}function ko(e,t,n,r,i){if(!Oo(e))return null;let a=t.output;xo(n)&&n.adoptWorkerState(a,t.state,e.times);let o=Math.min(e.from,e.times.length);return o===e.times.length&&e.data.length===o?a:n.update?.(i(),r,a,o)??null}var Ao=class{worker=null;jobs=new Map;sharedBars=null;constructor(e){this.host=e}use(e,t){this.settle(),this.worker=e?{client:e,minBars:t.minBars??5e4,onLand:t.onLand??null}:null}computing(e){if(e===void 0)return this.jobs.size>0;if(this.jobs.has(e))return!0;let t=this.host.instance(e);return!!t&&this.jobReadBy(t,this.jobs)!==null}stop(){this.worker?.client.cancel([...this.jobs.values()].map(e=>e.requestId)),this.jobs.clear(),this.worker=null}barsChanged(){this.sharedBars=null}takes(e,t,n){if(!this.worker&&this.jobs.size===0)return!1;let r=e.config.instanceId,i=this.jobs.get(r);return i&&n!==void 0?(i.from=Math.min(i.from,n),i.data=t,!0):(i&&this.drop(r),this.jobReadBy(e,this.jobs)?!0:n===void 0&&this.send(e,t))}drop(e){let t=this.jobs.get(e);t&&(this.jobs.delete(e),this.worker?.client.cancel([t.requestId]))}settle(){if(this.jobs.size===0)return;this.host.runPending();let e=this.jobs;this.jobs=new Map,this.worker?.client.cancel([...e.values()].map(e=>e.requestId));for(let t of this.host.ordered()){let n=e.get(t.config.instanceId)??this.jobReadBy(t,e);n&&this.host.compute(t,n.data,void 0,!0)}this.worker?.onLand?.()}send(e,t){let n=this.worker,{plugin:r,config:i}=e;if(!n?.client.usable||t.length<n.minBars||!Pa.has(r))return!1;let a=ya(r.descriptor,i.params);if(a.kind===`line`)return!1;let o=i.instanceId,s=this.barsFor(t),c=Do(n.client,r,i,s,a,(e,t)=>this.land(o,e,t));return c?(this.jobs.set(o,c),!0):!1}barsFor(e){let t=this.sharedBars;if(t?.data===e&&t.times.length===e.length)return t;let n=Eo(e);return this.sharedBars=n,queueMicrotask(()=>{this.sharedBars===n&&(this.sharedBars=null)}),n}jobReadBy(e,t){if(t.size===0)return null;let n=ya(e.plugin.descriptor,e.config.params),r=new Set;for(;n.kind===`line`&&!r.has(n.instanceId);){let e=t.get(n.instanceId);if(e)return e;r.add(n.instanceId);let i=this.host.instance(n.instanceId);if(!i)return null;n=ya(i.plugin.descriptor,i.config.params)}return null}land(e,t,n){let r=this.jobs.get(e);if(r?.requestId!==t)return;this.host.runPending();let i=this.host.instance(e);if(this.jobs.get(e)!==r||!i)return;this.jobs.delete(e),this.apply(i,r,n);let a=new Set(this.host.dependents(e));for(let e of this.host.ordered())a.has(e.config.instanceId)&&this.host.compute(e,r.data);this.worker?.onLand?.()}apply(e,t,n){let{plugin:r,config:i}=e;delete e.sourceBars;let a=n instanceof Error?null:n,o=a&&ko(t,a,r,i,()=>jo(e,t.data));if(!o){this.host.compute(e,t.data,void 0,!0);return}e.output=o,e.changedFrom=0}};function jo(e,t){let n=ya(e.plugin.descriptor,e.config.params);return n.kind===`price`?(e.sourceBars=ba(t,n.source),e.sourceBars):t}var Mo=1;function No(e){return e.descriptor.readsExchangeTimeZone??!Pa.has(e)}var Po=class{registry=new Map;instances=new Map;styleDefaults=new Map;order=null;pending=null;timeframe=null;exchangeTimeZone=null;barsTimed=!0;worker=new Ao({instance:e=>this.instances.get(e),ordered:()=>this.ordered(),dependents:e=>this.getDependents(e),compute:(e,t,n,r)=>this.compute(e,t,n,r),runPending:()=>this.runPending()});useWorker(e,t={}){this.worker.use(e,t)}register(e){this.registry.set(e.descriptor.id,e)}getAvailableIndicators(){return Array.from(this.registry.values()).map(e=>e.descriptor)}addIndicator(e,t={},n,r={}){let i=this.registry.get(e);if(!i)throw Error(`Unknown indicator: ${e}`);let a=this.claimInstanceId(e,r.instanceId),o={id:e,instanceId:a,params:{...i.descriptor.defaultConfig,...t},visible:!0};r.pane&&this.canHost(r.pane)&&(o.pane=r.pane),r.scale===`left`&&i.descriptor.placement===`overlay`&&!o.pane&&(o.scale=`left`),this.exchangeTimeZone&&(o.exchangeTimeZone=this.exchangeTimeZone);let s=this.styleDefaults.get(e),c={...s?.plots,...o.style?.plots},l={colors:o.style?.colors??s?.colors?.slice()??Aa(_a([...this.instances.values()],e,i.descriptor.placement,o.pane??null)),lineWidths:o.style?.lineWidths??s?.lineWidths?.slice()??[1.5],opacity:o.style?.opacity??s?.opacity??1,...Object.keys(c).length>0?{plots:Ma(c)}:{}};this.runPending();let u={plugin:i,config:o,output:null,style:l,changedFrom:0,offInterval:!1,offChartType:!1};return this.placeOnChartType(u),this.instances.set(a,u),this.order=null,n&&this.compute(u,n),a}removeIndicator(e){this.worker.drop(e),this.instances.delete(e),this.order=null}updateIndicator(e,t,n){this.runPending();let r=this.instances.get(e);if(!r)return;let i=va(r.plugin.descriptor);if(i&&i in t&&this.readsFromItself(e,{...r.config.params,...t})){let{[i]:e,...n}=t;t=n}if(Object.assign(r.config.params,t),delete r.sourceBars,delete r.lineInput,this.order=null,!n)return;let a=new Set([e,...this.getDependents(e)]);for(let e of this.ordered())a.has(e.config.instanceId)&&this.compute(e,n)}recalculateAll(e){this.pending=null;for(let t of this.ordered())this.compute(t,e)}deferRecalculateFrom(e,t){this.worker.barsChanged();let n=this.waitingOn(e);n.from=Math.min(n.from,t)}waitingOn(e){let t=this.pending;return t&&t.data===e?t:(this.runPending(),this.pending={data:e,from:1/0,full:new Set},this.pending)}flush(){this.worker.settle(),this.runPending()}runPending(){let e=this.pending;if(!e)return;this.pending=null;let{data:t,from:n,full:r}=e;for(let e of this.ordered())r.has(e.config.instanceId)?this.compute(e,t):n!==1/0&&this.compute(e,t,n)}recalculateFrom(e,t){this.deferRecalculateFrom(e,t),this.runPending()}compute(e,t,n,r=!1){if(!r&&this.worker.takes(e,t,n))return;let{plugin:i,config:a}=e,o=ya(i.descriptor,a.params);if(o.kind===`line`){this.computeFromLine(e,t,o.instanceId,o.key,n);return}delete e.lineInput;let s=t;o.kind===`price`?(e.sourceBars=ba(t,o.source,e.sourceBars??null,n??0),s=e.sourceBars):delete e.sourceBars;let c=e.output,l=null;n!==void 0&&n>0&&c&&i.update&&(l=i.update(s,a,c,n)),e.changedFrom=l?Math.max(0,n-(i.revisesBefore?.(a)??0)):0,e.output=l??i.calculate(s,a)}computeFromLine(e,t,n,r,i){let{plugin:a,config:o}=e,s=this.instances.get(n),c=s?.output?.series,l=e.lineInput,u=i===void 0?void 0:Math.min(i,s?.changedFrom??0);if(u!==void 0&&c&&a.update&&l&&l.raw.series&&l.aligned.series&&l.sourceId===n&&l.key===r&&l.start<u&&u<=l.start+l.bars.length){let{start:n,bars:i}=l;i.length=t.length-n;let s=i[u-1-n].close;for(let e=u;e<t.length;e++){let a=c[e]?.[r];a!==void 0&&Number.isFinite(a)&&(s=a),i[e-n]={time:t[e].time,open:s,high:s,low:s,close:s,volume:t[e].volume}}let d=a.update(i,o,l.raw,u-n);if(d?.series){let r=Math.max(n,u-(a.revisesBefore?.(o)??0));if(l.raw=d,n===0)l.aligned=d;else{let e=l.aligned.series;e.length=t.length;for(let i=r;i<t.length;i++)e[i]=d.series[i-n]??null;l.aligned.values=d.values,l.aligned.meta=d.meta}e.output=l.aligned,e.changedFrom=r;return}}e.changedFrom=0;let d=xa(t,c,r);if(!d){delete e.lineInput,e.output=Ca(t.length);return}let f=a.calculate(d.bars,o),p=Sa(f,d.start,t.length);e.lineInput={sourceId:n,key:r,start:d.start,bars:d.bars,raw:f,aligned:p},e.output=p}ordered(){if(this.order)return this.order;let e=[],t=new Map,n=r=>{let i=r.config.instanceId;if(t.get(i))return;t.set(i,`visiting`);let a=ya(r.plugin.descriptor,r.config.params),o=a.kind===`line`?this.instances.get(a.instanceId):void 0;o&&n(o),t.set(i,`done`),e.push(r)};for(let e of this.instances.values())n(e);return this.order=e,e}readsFromItself(e,t){let n=this.instances.get(e);if(!n)return!1;let r=ya(n.plugin.descriptor,t),i=new Set;for(;r.kind===`line`;){if(r.instanceId===e)return!0;if(i.has(r.instanceId))return!1;i.add(r.instanceId);let t=this.instances.get(r.instanceId);if(!t)return!1;r=ya(t.plugin.descriptor,t.config.params)}return!1}canHost(e){let t=this.instances.get(e);return!!t&&t.plugin.descriptor.placement===`panel`&&!t.config.pane}getDependents(e){let t=[],n=new Set([e]),r=[e];for(;r.length;){let e=r.shift();for(let i of this.instances.values()){let a=ya(i.plugin.descriptor,i.config.params),o=i.config.instanceId;a.kind===`line`&&a.instanceId===e&&!n.has(o)&&(n.add(o),t.push(o),r.push(o))}}return t}claimInstanceId(e,t){if(t&&!this.instances.has(t)){let e=Number(/_(\d+)$/.exec(t)?.[1]);return Number.isSafeInteger(e)&&e>=Mo&&(Mo=e+1),t}let n=`tc_${e}_${Mo++}`;for(;this.instances.has(n);)n=`tc_${e}_${Mo++}`;return n}getPaneMembers(e){let t=[];for(let n of this.instances.values())n.config.pane===e&&t.push(n.config.instanceId);return t}setPane(e,t){let n=this.instances.get(e);if(!n||t===e||t!==null&&!this.canHost(t))return!1;if(t===null?delete n.config.pane:(n.config.pane=t,delete n.config.scale),ja(n.style.colors)){let t=n.plugin.descriptor.placement,r=n.config.pane??null,i=[...this.instances.values()];ga(i,t,r,e).has(n.style.colors[0])&&(n.style.colors=Aa(_a(i,n.config.id,t,r,e)))}return!0}getOutput(e){return this.flush(),this.instances.get(e)?.output??null}peekOutput(e){return this.runPending(),this.instances.get(e)?.output??null}isComputingInWorker(e){return this.worker.computing(e)}stopWorker(){this.worker.stop()}renderOverlays(e,t,n){for(let r of this.overlayDraws(t,n))r(e)}overlayDraws(e,t){this.runPending();let n=[];for(let r of this.instances.values()){let i=r.output;if(!i||!oa(r)||r.plugin.descriptor.placement!==`overlay`||r.config.pane)continue;let a=r.config.scale===`left`?t??e:e;n.push(e=>r.plugin.render(e,i,a,r.style))}return n}hasLeftScaleOverlays(){return[...this.instances.values()].some(e=>e.config.scale===`left`&&oa(e))}setScale(e,t){let n=this.instances.get(e);return!n||n.plugin.descriptor.placement!==`overlay`||n.config.pane?!1:(t===`left`?n.config.scale=`left`:delete n.config.scale,!0)}renderPanel(e,t,n){this.runPending();let r=this.instances.get(t);!r?.output||!oa(r)||r.plugin.render(e,r.output,n,r.style)}getLatestValues(e){this.runPending();let t=this.instances.get(e);return t?la(t):[]}getLatestOverlayValues(e=`right`){return this.runPending(),ua(this.instances.values(),e)}getIndicatorConfig(e){return this.instances.get(e)?.config??null}setVisible(e,t){let n=this.instances.get(e);return n?(n.config.visible=t,t):null}isVisible(e){return this.instances.get(e)?.config.visible??!1}isShown(e){let t=this.instances.get(e);return t?oa(t):!1}setTimeframe(e){this.timeframe=e;let t=!1;for(let e of this.instances.values())t=this.placeOnInterval(e)||t;return t}setExchangeTimeZone(e,n){let r=e&&!(0,t.isUtcTimeZone)(e)&&(0,t.isValidTimeZone)(e)?e:null;if(r===this.exchangeTimeZone)return!1;this.exchangeTimeZone=r;for(let{config:e}of this.instances.values())r?e.exchangeTimeZone=r:delete e.exchangeTimeZone;if(n){let e=this.waitingOn(n).full;for(let t of this.zoneDependents())e.add(t)}return!0}zoneDependents(){let e=new Set;for(let t of this.instances.values())if(No(t.plugin)){e.add(t.config.instanceId);for(let n of this.getDependents(t.config.instanceId))e.add(n)}return e}setIntervals(e,t){let n=this.instances.get(e);if(!n)return!1;let r=t?ka(t):null;return r?n.config.intervals=r:delete n.config.intervals,this.placeOnInterval(n),!0}getIntervals(e){let t=this.instances.get(e)?.config.intervals;return t?Na(t):null}setBarsTimed(e){if(e===this.barsTimed)return!1;this.barsTimed=e;let t=!1;for(let e of this.instances.values())t=this.placeOnChartType(e)||t;return t}placeOnChartType(e){let t=Qa.has(e.config.id)||e.plugin.descriptor.readsExchangeTimeZone===!0,n=!this.barsTimed&&t;return n===e.offChartType?!1:(e.offChartType=n,!0)}placeOnInterval(e){let t=!Oa(e.config.intervals,this.timeframe);return t===e.offInterval?!1:(e.offInterval=t,!0)}getLevels(e){let t=this.instances.get(e);return t?[...t.config.levels??t.plugin.descriptor.levels??[]]:[]}setLevels(e,t){let n=this.instances.get(e);return n?(t===null?delete n.config.levels:n.config.levels=t.filter(e=>Number.isFinite(e)),!0):!1}getPaneValueRange(e,t,n,r=!1){return this.runPending(),da(this.paneInstances(e),t,n,r)}getPaneValuesAt(e,t){return this.runPending(),fa(this.paneInstances(e),t)}paneInstances(e){return[e,...this.getPaneMembers(e)].map(e=>this.instances.get(e)).filter(e=>e!==void 0)}getIndicatorDescriptor(e){return this.instances.get(e)?.plugin.descriptor??null}getActiveIndicators(){let e=[];for(let[t,n]of this.instances)e.push({instanceId:t,id:n.config.id,params:{...n.config.params},descriptor:n.plugin.descriptor,visible:n.config.visible??!0,shown:oa(n),...n.offChartType?{offChartType:!0}:{},...n.config.intervals?{intervals:Na(n.config.intervals)}:{},...n.config.pane?{pane:n.config.pane}:{},...n.config.scale===`left`?{scale:`left`}:{}});return e}orderIndicators(e){let t=new Map;for(let n of e){let e=this.instances.get(n);e&&!t.has(n)&&t.set(n,e)}for(let[e,n]of this.instances)t.has(e)||t.set(e,n);this.instances=t,this.order=null}getIndicatorStyle(e){let t=this.instances.get(e)?.style;return t?{colors:[...t.colors],lineWidths:[...t.lineWidths],opacity:t.opacity,...t.plots?{plots:Ma(t.plots)}:{}}:null}updateIndicatorStyle(e,t){let n=this.instances.get(e);if(!n)return;let{plots:r,...i}=t;if(Object.assign(n.style,i),r){let e=Ma(n.style.plots??{});for(let[t,n]of Object.entries(r))e[t]={...e[t],...n};n.style.plots=e}}setPlotStyles(e,t){let n=this.instances.get(e);n&&(t&&Object.keys(t).length>0?n.style.plots=Ma(t):delete n.style.plots)}setStyleDefaults(e,t){t?this.styleDefaults.set(e,{...t,...t.plots?{plots:Ma(t.plots)}:{}}):this.styleDefaults.delete(e)}getOverlayPriceRange(e,t,n=`right`){return this.runPending(),ha(this.instances.values(),e,t,n)}getPanelIndicators(){return[...this.instances.values()].filter(e=>e.plugin.descriptor.placement===`panel`).map(e=>({instanceId:e.config.instanceId,descriptor:e.plugin.descriptor}))}};function V(e,t,n){let r=e.params[t];if(typeof r==`number`&&Number.isFinite(r))return r;if(typeof r==`string`){let e=Number(r);if(Number.isFinite(e))return e}return n}function H(e,t,n,r=1){let i=V(e,t,n);return Math.max(r,Math.floor(i))}var Fo=class extends I{descriptor={id:`sma`,name:`Simple Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`SMA`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`SMA`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null),a=0;for(let t=0;t<e.length;t++)if(a+=e[t].close,t>=n&&(a-=e[t-n].close),t>=n-1){let o={value:a/n};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=H(t,`period`,20,1);for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0;for(let n=t-i+1;n<=t;n++)r+=e[n].close;this.writePoint(n,e,t,{value:r/i})}return n}},Io=class extends I{descriptor={id:`ema`,name:`Exponential Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`EMA`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`EMA`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=2/(n+1),i=new L,a=Array(e.length).fill(null),o=0;for(let t=0;t<e.length;t++){if(t<n-1){o+=e[t].close;continue}o=t===n-1?(o+e[t].close)/n:(e[t].close-o)*r+o;let s={value:o};i.set(e[t].time,s),a[t]=s}return{values:i,series:a}}update(e,t,n,r){let i=H(t,`period`,20,1);if(r<i||!this.canResume(e,n,r))return null;let a=n.series[r-1]?.value;if(a===void 0)return null;let o=2/(i+1);for(let t=r;t<e.length;t++)a=(e[t].close-a)*o+a,this.writePoint(n,e,t,{value:a});return n}},Lo=class extends I{descriptor={id:`bb`,name:`Bollinger Bands`,placement:`overlay`,defaultConfig:{period:20,stdDev:2,source:`close`},shortName:`BB`,inputs:{source:{source:!0},period:{kind:`int`,min:1},stdDev:{kind:`number`,min:.1,step:.1}},fills:[{between:[`upper`,`lower`],color:0,opacity:.1}],plots:[{key:`upper`,title:`Upper`,color:0},{key:`middle`,title:`Basis`,color:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=V(t,`stdDev`,2),i=new L,a=Array(e.length).fill(null),o=0,s=0;for(let t=0;t<e.length;t++){let c=e[t].close;if(o+=c,s+=c*c,t>=n){let r=e[t-n].close;o-=r,s-=r*r}if(t>=n-1){let c=o/n,l=s/n-c*c,u=Math.sqrt(Math.max(0,l)),d={middle:c,upper:c+r*u,lower:c-r*u};i.set(e[t].time,d),a[t]=d}}return{values:i,series:a}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=H(t,`period`,20,1),a=V(t,`stdDev`,2);for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0,o=0;for(let n=t-i+1;n<=t;n++){let t=e[n].close;r+=t,o+=t*t}let s=r/i,c=Math.sqrt(Math.max(0,o/i-s*s));this.writePoint(n,e,t,{middle:s,upper:s+a*c,lower:s-a*c})}return n}},Ro=[`session`,`week`,`month`,`all`],zo=64,Bo=2;function Vo(e){let t=e.params.anchor;return Ro.includes(t)?t:`session`}function Ho(e,t){let n=Vo(t);return n===`all`?null:Dt(e,n,t.exchangeTimeZone)}var Uo=class extends I{descriptor={readsExchangeTimeZone:!0,id:`vwap`,name:`Volume Weighted Average Price`,placement:`overlay`,defaultConfig:{anchor:`session`},shortName:`VWAP`,inputs:{anchor:{options:Ro}},plots:[{key:`value`,title:`VWAP`,color:0,breakOn:`session`}]};kept=new WeakMap;workerState(e){return this.kept.get(e)}adoptWorkerState(e,t){t&&this.kept.set(e,t)}calculate(e,t){let n={values:new L,series:Array(e.length).fill(null)},r=Ho(e,t),i=this.fill(n,e,r,0,null);return r&&this.kept.set(n,i),n}update(e,t,n,r){let i=Ho(e,t),a=this.kept.get(n)??[],o=a.find(e=>e.index===r-1);if(!i||!o||r<zo||r>=e.length||!this.canResume(e,n,r))return null;n.series.length=e.length;let s=this.fill(n,e,i,r,o),c=a.filter(t=>t.index<r&&t.index>=e.length-Bo);return this.kept.set(n,[...c,...s]),n}fill(e,t,n,r,i){let a=i&&n?n(t[i.index].time):void 0,o=i?.volume??0,s=i?.volumePrice??0,c=[];for(let i=r;i<t.length;i++){let r=t[i];if(n){let e=n(r.time);e!==a&&(o=0,s=0,a=e)}o+=r.volume,s+=(r.high+r.low+r.close)/3*r.volume,i>=t.length-Bo&&c.push({index:i,volume:o,volumePrice:s});let l=o>0?a===void 0?{value:s/o}:{value:s/o,session:a}:null;this.writePoint(e,t,i,l)}return c}},Wo=4,Go=t.TC_SERIES_COLORS[Wo],Ko=class extends I{descriptor={id:`ichimoku`,name:`Ichimoku Cloud`,placement:`overlay`,defaultConfig:{tenkan:9,kijun:26,senkou:52,displacement:26},inputs:{tenkan:{kind:`int`,min:1},kijun:{kind:`int`,min:1},senkou:{kind:`int`,min:1},displacement:{kind:`int`,min:0}},shortName:`Ichimoku`,plots:[{key:`tenkan`,title:`Conversion`,color:0},{key:`kijun`,title:`Base`,color:1},{key:`senkouA`,title:`Lead A`,color:2},{key:`senkouB`,title:`Lead B`,color:3},{key:`chikou`,title:`Lagging Span`,color:Wo}]};calculate(e,t){let n=H(t,`tenkan`,9,1),r=H(t,`kijun`,26,1),i=H(t,`senkou`,52,1),a=H(t,`displacement`,26,0),o=new L,s=Array(e.length).fill(null),c=t=>{let n=new Float64Array(e.length),r=new Float64Array(e.length);for(let i=0;i<e.length;i++){let a=-1/0,o=1/0,s=Math.max(0,i-t+1);for(let t=s;t<=i;t++)e[t].high>a&&(a=e[t].high),e[t].low<o&&(o=e[t].low);n[i]=a,r[i]=o}return{highs:n,lows:r}},l=c(n),u=c(r),d=c(i),f=(e,t,n)=>n>=t-1?(e.highs[n]+e.lows[n])/2:void 0,p=e=>{let t=f(l,n,e),a=f(u,r,e),o={};t!==void 0&&a!==void 0&&(o.senkouA=(t+a)/2);let s=f(d,i,e);return s!==void 0&&(o.senkouB=s),o};for(let t=0;t<e.length;t++){let i={},c=f(l,n,t);c!==void 0&&(i.tenkan=c);let d=f(u,r,t);d!==void 0&&(i.kijun=d),t>=a&&Object.assign(i,p(t-a)),t+a<e.length&&(i.chikou=e[t+a].close),Object.keys(i).length>0&&(o.set(e[t].time,i),s[t]=i)}let m=Math.max(0,e.length-a),h=[];for(let t=m;t<e.length;t++)h.push(p(t));return{values:o,series:s,meta:{ahead:h,aheadFrom:m+a}}}render(n,r,i,a){let o=r.series;if(!o)return;let{from:s,to:c}=i.visibleRange,l=r.meta?.ahead,u=r.meta?.aheadFrom??o.length,d=c-s+1,f=d+(l?.length??0),p=new Float64Array(d),m=new Float64Array(d),h=0,g=new Float64Array(d),_=new Float64Array(d),v=0,y=new Float64Array(f),b=new Float64Array(f),x=0,S=new Float64Array(f),C=new Float64Array(f),w=0,T=new Float64Array(d),E=new Float64Array(d),D=0,O=new Float64Array(f),k=new Float64Array(f),A=new Float64Array(f),j=0,ee=(t,n)=>{let r=n.senkouA,a=n.senkouB;r!==void 0&&(y[x]=t,b[x]=e.T(r,i),x++),a!==void 0&&(S[w]=t,C[w]=e.T(a,i),w++),r!==void 0&&a!==void 0&&(O[j]=t,k[j]=b[x-1],A[j]=C[w-1],j++)};for(let t=s;t<=c&&t<o.length;t++){let n=o[t];if(!n)continue;let r=e.b(t,i);n.tenkan!==void 0&&(p[h]=r,m[h]=e.T(n.tenkan,i),h++),n.kijun!==void 0&&(g[v]=r,_[v]=e.T(n.kijun,i),v++),ee(r,n),n.chikou!==void 0&&(T[D]=r,E[D]=e.T(n.chikou,i),D++)}if(l){let t=i.chartRect.x-i.barWidth-i.barSpacing,n=i.chartRect.x+i.chartRect.width+i.barWidth+i.barSpacing;for(let r=0;r<l.length;r++){let a=e.b(u+r,i);if(a>n)break;a>=t&&ee(a,l[r])}}if(j>1){n.beginPath(),n.moveTo(O[0],k[0]);for(let e=1;e<j;e++)n.lineTo(O[e],k[e]);for(let e=j-1;e>=0;e--)n.lineTo(O[e],A[e]);n.closePath(),n.fillStyle=(0,t.withAlpha)(a.colors[2]??`#1fa874`,.15),n.fill()}let te=(e,t,r,i,o,s)=>{let c=Ki(a,e,s);if(!(i<2||!c.visible)){n.beginPath(),n.strokeStyle=o,n.lineWidth=s,n.lineJoin=`round`,n.setLineDash(c.dash),n.moveTo(t[0],r[0]);for(let e=1;e<i;e++)n.lineTo(t[e],r[e]);n.stroke(),n.setLineDash([])}};te(`tenkan`,p,m,h,a.colors[0],a.lineWidths[0]),te(`kijun`,g,_,v,a.colors[1]??`#f2a93b`,a.lineWidths[0]),te(`senkouA`,y,b,x,a.colors[2]??`#1fa874`,1),te(`senkouB`,S,C,w,a.colors[3]??`#e8505b`,1),te(`chikou`,T,E,D,a.colors[Wo]??Go,1)}},qo=class extends I{descriptor={id:`psar`,name:`Parabolic SAR`,placement:`overlay`,defaultConfig:{step:.02,max:.2},inputs:{step:{kind:`number`,min:.01,step:.01},max:{kind:`number`,min:.01,step:.01}},shortName:`SAR`,plots:[{key:`value`,title:`SAR`,color:0,kind:`dots`,tone:{field:`trend`},downColor:1}]};calculate(e,t){let n=V(t,`step`,.02),r=V(t,`max`,.2),i=new L,a=Array(e.length).fill(null);if(e.length<2)return{values:i,series:a};let o=e[1].close>e[0].close,s=n,c=o?e[0].high:e[0].low,l=o?e[0].low:e[0].high,u={value:l,trend:o?1:-1};i.set(e[0].time,u),a[0]=u;for(let t=1;t<e.length;t++){let u=l;l=u+s*(c-u),o?(l=Math.min(l,e[t-1].low),t>=2&&(l=Math.min(l,e[t-2].low)),e[t].low<l?(o=!1,l=c,c=e[t].low,s=n):e[t].high>c&&(c=e[t].high,s=Math.min(s+n,r))):(l=Math.max(l,e[t-1].high),t>=2&&(l=Math.max(l,e[t-2].high)),e[t].high>l?(o=!0,l=c,c=e[t].high,s=n):e[t].low<c&&(c=e[t].low,s=Math.min(s+n,r)));let d={value:l,trend:o?1:-1};i.set(e[t].time,d),a[t]=d}return{values:i,series:a}}},Jo=class extends I{descriptor={id:`supertrend`,name:`Supertrend`,placement:`overlay`,defaultConfig:{period:10,multiplier:3},inputs:{period:{kind:`int`,min:1},multiplier:{kind:`number`,min:.1,step:.1}},shortName:`Supertrend`,plots:[{key:`value`,title:`Supertrend`,color:0,tone:{field:`trend`},downColor:1}]};calculate(e,t){let n=H(t,`period`,10,1),r=V(t,`multiplier`,3),i=new L,a=Array(e.length).fill(null);if(e.length<n)return{values:i,series:a};let o=[e[0].high-e[0].low];for(let t=1;t<e.length;t++)o.push(Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close)));let s=0;for(let e=0;e<n;e++)s+=o[e];s/=n;let c=0,l=0,u=0,d=0,f=0,p=0,m=1;for(let t=n-1;t<e.length;t++){t>n-1&&(s=(s*(n-1)+o[t])/n);let h=(e[t].high+e[t].low)/2,g=h+r*s,_=h-r*s,v=e[Math.max(0,t-1)].close;c=g<u||v>u?g:u,l=_>d||v<d?_:d,f=p===u?e[t].close<=c?c:l:e[t].close>=l?l:c,m=f===l?1:-1;let y={value:f,trend:m};i.set(e[t].time,y),a[t]=y,u=c,d=l,p=f}return{values:i,series:a}}},Yo=class extends I{descriptor={id:`keltner`,name:`Keltner Channel`,placement:`overlay`,defaultConfig:{emaPeriod:20,atrPeriod:10,multiplier:1.5},inputs:{emaPeriod:{kind:`int`,min:1},atrPeriod:{kind:`int`,min:1},multiplier:{kind:`number`,min:.1,step:.1}},shortName:`KC`,fills:[{between:[`upper`,`lower`],color:0,opacity:.08}],plots:[{key:`upper`,title:`Upper`,color:0},{key:`middle`,title:`Basis`,color:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=H(t,`emaPeriod`,20,1),r=H(t,`atrPeriod`,10,1),i=V(t,`multiplier`,1.5),a=new L;if(e.length<Math.max(n,r))return{values:a};let o=2/(n+1),s=e[0].close,c=[s];for(let t=1;t<e.length;t++)s=(e[t].close-s)*o+s,c.push(s);let l=[e[0].high-e[0].low];for(let t=1;t<e.length;t++)l.push(Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close)));let u=0;for(let e=0;e<r;e++)u+=l[e];u/=r;let d=Array(e.length).fill(null),f=Math.max(n,r)-1;for(let t=f;t<e.length;t++){t>f&&(u=(u*(r-1)+l[t])/r);let n={middle:c[t],upper:c[t]+i*u,lower:c[t]-i*u};a.set(e[t].time,n),d[t]=n}return{values:a,series:d}}},Xo=class extends I{descriptor={id:`donchian`,name:`Donchian Channel`,placement:`overlay`,defaultConfig:{period:20},inputs:{period:{kind:`int`,min:1}},shortName:`DC`,fills:[{between:[`upper`,`lower`],color:0,opacity:.08}],plots:[{key:`upper`,title:`Upper`,color:0},{key:`middle`,title:`Basis`,color:1,width:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s={upper:a,middle:(a+o)/2,lower:o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}},Zo=[`traditional`,`fibonacci`,`woodie`,`classic`,`camarilla`,`dm`],Qo=class extends I{descriptor={id:`pivots`,name:`Pivot Points`,placement:`overlay`,defaultConfig:{lookback:24,type:`traditional`},shortName:`Pivots`,inputs:{lookback:{kind:`int`,min:1},type:{options:Zo}},plots:[{key:`r3`,title:`R3`,color:1,width:1,lineStyle:`dashed`},{key:`r2`,title:`R2`,color:1,width:1,lineStyle:`dashed`},{key:`r1`,title:`R1`,color:1,width:1,lineStyle:`dashed`},{key:`pp`,title:`P`,color:0},{key:`s1`,title:`S1`,color:2,width:1,lineStyle:`dashed`},{key:`s2`,title:`S2`,color:2,width:1,lineStyle:`dashed`},{key:`s3`,title:`S3`,color:2,width:1,lineStyle:`dashed`}]};calculate(e,t){let n=H(t,`lookback`,24,1),r=Zo.includes(t.params.type)?t.params.type:`traditional`,i=new L,a=Array(e.length).fill(null);if(e.length<=n)return{values:i,series:a};for(let t=n;t<e.length;t++){let o=-1/0,s=1/0;for(let r=t-n;r<t;r++)e[r].high>o&&(o=e[r].high),e[r].low<s&&(s=e[r].low);let c=$o(r,e[t-n].open,o,s,e[t-1].close);i.set(e[t].time,c),a[t]=c}return{values:i,series:a}}};function $o(e,t,n,r,i){let a=n-r;if(e===`dm`){let e=i<t?n+2*r+i:i>t?2*n+r+i:n+r+2*i;return{pp:e/4,r1:e/2-r,s1:e/2-n}}if(e===`camarilla`){let e=a*1.1;return{pp:(n+r+i)/3,r1:i+e/12,s1:i-e/12,r2:i+e/6,s2:i-e/6,r3:i+e/4,s3:i-e/4}}let o=e===`woodie`?(n+r+2*i)/4:(n+r+i)/3;if(e===`fibonacci`)return{pp:o,r1:o+.382*a,s1:o-.382*a,r2:o+.618*a,s2:o-.618*a,r3:o+a,s3:o-a};let s=2*o-r,c=2*o-n;return e===`classic`?{pp:o,r1:s,s1:c,r2:o+a,s2:o-a,r3:o+2*a,s3:o-2*a}:{pp:o,r1:s,s1:c,r2:o+a,s2:o-a,r3:n+2*(o-r),s3:r-2*(n-o)}}var es=class extends I{descriptor={id:`avwap`,name:`Anchored VWAP`,placement:`overlay`,defaultConfig:{anchorTime:0},inputs:{anchorTime:{kind:`int`}},shortName:`AVWAP`,plots:[{key:`value`,title:`AVWAP`,color:0}]};calculate(e,n){let r=V(n,`anchorTime`,0),i=new L,a=Array(e.length).fill(null),o=0;if(r>0){let n=(0,t.barTimeUnit)(e),s=(0,t.normalizeBarTime)(r);if(o=e.findIndex(e=>e.time*n>=s),o<0)return{values:i,series:a}}let s=0,c=0;for(let t=o;t<e.length;t++){let n=(e[t].high+e[t].low+e[t].close)/3;if(s+=e[t].volume,c+=n*e[t].volume,s>0){let n={value:c/s};i.set(e[t].time,n),a[t]=n}}return{values:i,series:a}}},ts=class extends I{descriptor={id:`zigzag`,name:`ZigZag`,placement:`overlay`,defaultConfig:{deviation:5},inputs:{deviation:{kind:`number`,min:.1,step:.1}},shortName:`ZigZag`,plots:[{key:`pivot`,title:`Pivot`,color:0}]};calculate(e,t){let n=Math.max(.01,V(t,`deviation`,5))/100,r=new L,i=Array(e.length).fill(null);if(e.length<2)return{values:r,series:i,meta:{pivots:[]}};let a=[],o=null,s=0,c=e[0].close;for(let t=1;t<e.length;t++){let r=e[t].high,i=e[t].low;if(o===null){r>=c*(1+n)?(a.push({idx:s,price:c,type:`low`}),o=`up`,s=t,c=r):i<=c*(1-n)&&(a.push({idx:s,price:c,type:`high`}),o=`down`,s=t,c=i);continue}o===`up`?r>c?(s=t,c=r):i<=c*(1-n)&&(a.push({idx:s,price:c,type:`high`}),o=`down`,s=t,c=i):i<c?(s=t,c=i):r>=c*(1+n)&&(a.push({idx:s,price:c,type:`low`}),o=`up`,s=t,c=r)}a.push({idx:s,price:c,type:o===`up`?`high`:`low`});for(let t of a){let n={pivot:t.price};r.set(e[t.idx].time,n),i[t.idx]=n}return{values:r,series:i,meta:{pivots:a}}}render(t,n,r,i){if(i.plots?.pivot?.visible===!1)return;let a=n.meta?.pivots;if(!(!a||a.length<2)){t.beginPath(),t.strokeStyle=i.colors[0],t.lineWidth=i.lineWidths[0],t.lineJoin=`round`;for(let n=0;n<a.length;n++){let i=a[n],o=e.b(i.idx,r),s=e.T(i.price,r);n===0?t.moveTo(o,s):t.lineTo(o,s)}t.stroke()}}},ns=class extends I{descriptor={id:`lrc`,name:`Linear Regression Channel`,placement:`overlay`,defaultConfig:{period:100,stdDev:2,source:`close`},shortName:`LRC`,inputs:{source:{source:!0},period:{kind:`int`,min:2},stdDev:{kind:`number`,min:.1,step:.1}},fills:[{between:[`upper`,`lower`],color:0,opacity:.08}],plots:[{key:`upper`,title:`Upper`,color:0},{key:`middle`,title:`Basis`,color:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=H(t,`period`,100,2),r=V(t,`stdDev`,2),i=new L,a=Array(e.length).fill(null);if(e.length<n)return{values:i,series:a};for(let t=n-1;t<e.length;t++){let o=t-n+1,s=0,c=0,l=0,u=0;for(let t=0;t<n;t++){let n=t,r=e[o+t].close;s+=n,c+=r,l+=n*r,u+=n*n}let d=n*u-s*s;if(d===0)continue;let f=(n*l-s*c)/d,p=(c-f*s)/n,m=0;for(let t=0;t<n;t++){let n=f*t+p,r=e[o+t].close-n;m+=r*r}let h=Math.sqrt(m/n),g=f*(n-1)+p,_={middle:g,upper:g+r*h,lower:g-r*h,slope:f};i.set(e[t].time,_),a[t]=_}return{values:i,series:a}}},rs=class extends I{descriptor={id:`hma`,name:`Hull Moving Average`,placement:`overlay`,defaultConfig:{period:21,source:`close`},shortName:`HMA`,inputs:{source:{source:!0},period:{kind:`int`,min:2}},plots:[{key:`value`,title:`HMA`,color:0}]};calculate(e,t){let n=H(t,`period`,21,2),r=new L,i=Array(e.length).fill(null);if(e.length<n)return{values:r,series:i};let a=e.map(e=>e.close),o=Math.max(2,Math.floor(n/2)),s=Math.max(2,Math.floor(Math.sqrt(n))),c=is(a,n),l=is(a,o),u=as(a.map((e,t)=>c[t]===null||l[t]===null?null:2*l[t]-c[t]),s);for(let t=0;t<e.length;t++){if(u[t]===null)continue;let n={value:u[t]};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}};function is(e,t){let n=Array(e.length).fill(null);if(e.length<t)return n;let r=t*(t+1)/2;for(let i=t-1;i<e.length;i++){let a=0;for(let n=0;n<t;n++)a+=e[i-n]*(t-n);n[i]=a/r}return n}function as(e,t){let n=Array(e.length).fill(null),r=t*(t+1)/2;for(let i=t-1;i<e.length;i++){let a=0,o=!0;for(let n=0;n<t;n++){let r=e[i-n];if(r===null){o=!1;break}a+=r*(t-n)}o&&(n[i]=a/r)}return n}var os=class extends I{descriptor={readsExchangeTimeZone:!0,id:`mtfma`,name:`MTF Moving Average`,placement:`overlay`,defaultConfig:{period:50,timeframe:`1d`,source:`close`},shortName:`MTF MA`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`MA`,color:0}]};calculate(e,t){let n=H(t,`period`,50,1),r=String(t.params.timeframe??`1d`),i=new L,a=Array(e.length).fill(null);if(e.length===0)return{values:i,series:a};let o=[],s=Dt(e,r,t.exchangeTimeZone),c=s(e[0].time),l=e[0].close,u=null,d=()=>{if(o.length<n)return;let e=0;for(let t=o.length-n;t<o.length;t++)e+=o[t];u=e/n};for(let t=0;t<e.length;t++){let n=s(e[t].time);if(n!==c&&(o.push(l),d(),c=n),l=e[t].close,u!==null){let n={value:u};i.set(e[t].time,n),a[t]=n}}return{values:i,series:a}}},ss=class extends I{descriptor={readsExchangeTimeZone:!0,id:`svwap`,name:`Session VWAP`,placement:`overlay`,defaultConfig:{bands:1},inputs:{bands:{kind:`int`,min:0,max:3}},shortName:`SVWAP`,plots:[{key:`value`,title:`VWAP`,color:0,breakOn:`session`},{key:`u1`,title:`+1σ`,color:1,width:1,lineStyle:`dashed`,opacity:.55,breakOn:`session`},{key:`l1`,title:`−1σ`,color:1,width:1,lineStyle:`dashed`,opacity:.55,breakOn:`session`},{key:`u2`,title:`+2σ`,color:1,width:1,lineStyle:`dashed`,opacity:.55,breakOn:`session`},{key:`l2`,title:`−2σ`,color:1,width:1,lineStyle:`dashed`,opacity:.55,breakOn:`session`},{key:`u3`,title:`+3σ`,color:1,width:1,lineStyle:`dashed`,opacity:.55,breakOn:`session`},{key:`l3`,title:`−3σ`,color:1,width:1,lineStyle:`dashed`,opacity:.55,breakOn:`session`}]};calculate(e,n){let r=(0,t.barsAreDaily)(e)===!0?0:Math.min(3,H(n,`bands`,1,0)),i=new L,a=Array(e.length).fill(null);if(e.length===0)return{values:i,series:a};let o=Dt(e,`session`,n.exchangeTimeZone),s=o(e[0].time),c=0,l=0,u=0;for(let t=0;t<e.length;t++){let n=e[t],d=o(n.time);d!==s&&(c=0,l=0,u=0,s=d);let f=(n.high+n.low+n.close)/3;if(c+=f*n.volume,l+=f*f*n.volume,u+=n.volume,u>0){let e=c/u,o={value:e,session:s};if(r>0){let t=Math.max(0,l/u-e*e),n=Math.sqrt(t);for(let t=1;t<=r;t++)o[`u${t}`]=e+t*n,o[`l${t}`]=e-t*n}i.set(n.time,o),a[t]=o}}return{values:i,series:a}}},cs=class extends I{descriptor={id:`chandelier`,name:`Chandelier Exit`,placement:`overlay`,defaultConfig:{period:22,multiplier:3},inputs:{period:{kind:`int`,min:1},multiplier:{kind:`number`,min:.1,step:.1}},shortName:`CE`,plots:[{key:`long`,title:`Long`,color:0,lineStyle:`dashed`},{key:`short`,title:`Short`,color:1,lineStyle:`dashed`}]};calculate(e,t){let n=H(t,`period`,22,1),r=V(t,`multiplier`,3),i=new L,a=Array(e.length).fill(null),o=e.length;if(o<=n)return{values:i,series:a};let s=Array(o).fill(0);for(let t=1;t<o;t++){let n=e[t-1].close;s[t]=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-n),Math.abs(e[t].low-n))}let c=0;for(let e=1;e<=n;e++)c+=s[e];c/=n;for(let t=n;t<o;t++){t>n&&(c=(c*(n-1)+s[t])/n);let o=-1/0,l=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>o&&(o=e[r].high),e[r].low<l&&(l=e[r].low);let u={long:o-r*c,short:l+r*c};i.set(e[t].time,u),a[t]=u}return{values:i,series:a}}},ls=class extends I{descriptor={id:`alligator`,name:`Alligator`,placement:`overlay`,defaultConfig:{jaw:13,teeth:8,lips:5,jawShift:8,teethShift:5,lipsShift:3},inputs:{jaw:{kind:`int`,min:1},teeth:{kind:`int`,min:1},lips:{kind:`int`,min:1},jawShift:{kind:`int`,min:0},teethShift:{kind:`int`,min:0},lipsShift:{kind:`int`,min:0}},shortName:`Alligator`,plots:[{key:`jaw`,title:`Jaw`,color:0},{key:`teeth`,title:`Teeth`,color:1},{key:`lips`,title:`Lips`,color:2}]};calculate(e,t){let n=H(t,`jaw`,13,1),r=H(t,`teeth`,8,1),i=H(t,`lips`,5,1),a=H(t,`jawShift`,8,0),o=H(t,`teethShift`,5,0),s=H(t,`lipsShift`,3,0),c=new L,l=e.length,u=Array(l).fill(null);if(l===0)return{values:c,series:u};let d=e.map(e=>(e.high+e.low)/2),f=us(d,n),p=us(d,r),m=us(d,i),h=Array(l).fill(void 0),g=Array(l).fill(void 0),_=Array(l).fill(void 0);for(let e=0;e<l;e++)f[e]!==void 0&&e+a<l&&(h[e+a]=f[e]),p[e]!==void 0&&e+o<l&&(g[e+o]=p[e]),m[e]!==void 0&&e+s<l&&(_[e+s]=m[e]);for(let t=0;t<l;t++){if(h[t]===void 0&&g[t]===void 0&&_[t]===void 0)continue;let n={};h[t]!==void 0&&(n.jaw=h[t]),g[t]!==void 0&&(n.teeth=g[t]),_[t]!==void 0&&(n.lips=_[t]),c.set(e[t].time,n),u[t]=n}return{values:c,series:u}}};function us(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<t)return r;let i=0;for(let n=0;n<t;n++)i+=e[n];let a=i/t;r[t-1]=a;for(let i=t;i<n;i++)a=(a*(t-1)+e[i])/t,r[i]=a;return r}var ds=class extends I{descriptor={id:`vwma`,name:`Volume Weighted Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`VWMA`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`VWMA`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null),a=0,o=0;for(let t=0;t<e.length;t++){let s=e[t].close*e[t].volume;if(a+=s,o+=e[t].volume,t>=n){let r=e[t-n];a-=r.close*r.volume,o-=r.volume}if(t>=n-1&&o>0){let n={value:a/o};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=H(t,`period`,20,1);for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0,a=0;for(let n=t-i+1;n<=t;n++)r+=e[n].close*e[n].volume,a+=e[n].volume;this.writePoint(n,e,t,a>0?{value:r/a}:null)}return n}},fs=class extends I{descriptor={id:`wma`,name:`Weighted Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`WMA`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`WMA`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null),a=n*(n+1)/2,o=0,s=0;for(let t=0;t<e.length;t++){let c=e[t].close;if(s+=c*n-o,o+=c,t>=n&&(o-=e[t-n].close),t>=n-1){let n={value:s/a};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=H(t,`period`,20,1),a=i*(i+1)/2;for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0,o=t-i+1;for(let t=0;t<i;t++)r+=e[o+t].close*(t+1);this.writePoint(n,e,t,{value:r/a})}return n}},ps=class extends I{descriptor={id:`envelope`,name:`Moving Average Envelope`,placement:`overlay`,defaultConfig:{period:20,percent:2.5,source:`close`},shortName:`Env`,inputs:{source:{source:!0},period:{kind:`int`,min:1},percent:{kind:`number`,min:0,step:.1}},fills:[{between:[`upper`,`lower`],color:0,opacity:.08}],plots:[{key:`upper`,title:`Upper`,color:0},{key:`basis`,title:`Basis`,color:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=V(t,`percent`,2.5)/100,i=new L,a=Array(e.length).fill(null),o=0;for(let t=0;t<e.length;t++)if(o+=e[t].close,t>=n&&(o-=e[t-n].close),t>=n-1){let s=o/n,c={basis:s,upper:s*(1+r),lower:s*(1-r)};i.set(e[t].time,c),a[t]=c}return{values:i,series:a}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=H(t,`period`,20,1),a=V(t,`percent`,2.5)/100;for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0;for(let n=t-i+1;n<=t;n++)r+=e[n].close;let o=r/i;this.writePoint(n,e,t,{basis:o,upper:o*(1+a),lower:o*(1-a)})}return n}};function ms(e,t){let n=2/(t+1),r=Array(e.length).fill(null),i=0,a=0;for(let o=0;o<e.length;o++){if(o<t-1){a+=e[o];continue}i=o===t-1?(a+e[o])/t:(e[o]-i)*n+i,r[o]=i}return r}function hs(e,t,n){let r=Array(n).fill(null);for(let n=0;n<e.length;n++)e[n]!==null&&(r[t[n]]=e[n]);return r}function gs(e){let t=[],n=[];for(let r=0;r<e.length;r++)e[r]!==null&&(t.push(e[r]),n.push(r));return{values:t,indices:n}}var _s=class extends I{descriptor={id:`tema`,name:`Triple EMA`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`TEMA`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`TEMA`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null),a=ms(e.map(e=>e.close),n),o=gs(a),s=hs(ms(o.values,n),o.indices,e.length),c=gs(s),l=hs(ms(c.values,n),c.indices,e.length);for(let t=0;t<e.length;t++){let n=a[t],o=s[t],c=l[t];if(n===null||o===null||c===null)continue;let u={value:3*n-3*o+c};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}},vs=class extends I{descriptor={id:`ao`,name:`Awesome Oscillator`,placement:`panel`,defaultConfig:{fast:5,slow:34},inputs:{fast:{kind:`int`,min:1},slow:{kind:`int`,min:1}},shortName:`AO`,plots:[{key:`value`,title:`AO`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}]};calculate(e,t){let n=H(t,`fast`,5,1),r=H(t,`slow`,34,1),i=new L,a=Array(e.length).fill(null);if(e.length<r)return{values:i,series:a};let o=Array(e.length);for(let t=0;t<e.length;t++)o[t]=(e[t].high+e[t].low)/2;let s=0,c=0,l;for(let t=0;t<e.length;t++)if(c+=o[t],t>=r&&(c-=o[t-r]),s+=o[t],t>=n&&(s-=o[t-n]),t>=r-1){let o=s/n-c/r,u={value:o,up:+(l===void 0||o>=l)};i.set(e[t].time,u),a[t]=u,l=o}return{values:i,series:a}}},ys=class extends I{descriptor={id:`chaikinOsc`,name:`Chaikin Oscillator`,placement:`panel`,defaultConfig:{fast:3,slow:10},inputs:{fast:{kind:`int`,min:1},slow:{kind:`int`,min:1}},shortName:`Chaikin Osc`,plots:[{key:`value`,title:`Chaikin`,color:0,kind:`histogram`,tone:`sign`,downColor:1}]};calculate(e,t){let n=H(t,`fast`,3,1),r=H(t,`slow`,10,1),i=new L,a=Array(e.length).fill(null);if(e.length<r)return{values:i,series:a};let o=2/(n+1),s=2/(r+1),c=0,l=0,u=0;for(let t=0;t<e.length;t++){let{high:n,low:d,close:f,volume:p}=e[t],m=n-d,h=m===0?0:(f-d-(n-f))/m;if(c+=h*p,t===0?(l=c,u=c):(l=(c-l)*o+l,u=(c-u)*s+u),t>=r-1){let n={value:l-u,adl:c};i.set(e[t].time,n),a[t]=n}}return{values:i,series:a}}},bs=class extends I{descriptor={id:`rsi`,name:`Relative Strength Index`,placement:`panel`,defaultConfig:{period:14,source:`close`},shortName:`RSI`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`RSI`,color:0}],scale:{min:0,max:100},levels:[30,70]};smoothing=new WeakMap;workerState(e){return this.smoothing.get(e)}adoptWorkerState(e,t){t&&this.smoothing.set(e,t)}calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null),a={values:r,series:i};if(e.length<n+1)return a;let o=[],s=[],c=0,l=0;for(let t=1;t<=n;t++){let n=e[t].close-e[t-1].close;n>0?c+=n:l-=n}c/=n,l/=n,o[n]=c,s[n]=l;let u={value:l===0?100:100-100/(1+c/l)};r.set(e[n].time,u),i[n]=u;for(let t=n+1;t<e.length;t++){let a=e[t].close-e[t-1].close,u=a>0?a:0,d=a<0?-a:0;c=(c*(n-1)+u)/n,l=(l*(n-1)+d)/n,o[t]=c,s[t]=l;let f={value:l===0?100:100-100/(1+c/l)};r.set(e[t].time,f),i[t]=f}return this.smoothing.set(a,{gain:o,loss:s}),a}update(e,t,n,r){let i=H(t,`period`,14,1),a=this.smoothing.get(n);if(!a||r<=i||!this.canResume(e,n,r))return null;let o=a.gain[r-1],s=a.loss[r-1];if(o===void 0||s===void 0)return null;for(let t=r;t<e.length;t++){let r=e[t].close-e[t-1].close,c=r>0?r:0,l=r<0?-r:0;o=(o*(i-1)+c)/i,s=(s*(i-1)+l)/i,a.gain[t]=o,a.loss[t]=s;let u=s===0?100:100-100/(1+o/s);this.writePoint(n,e,t,{value:u})}return n}},xs=class extends I{descriptor={id:`macd`,name:`MACD`,placement:`panel`,defaultConfig:{fast:12,slow:26,signal:9,source:`close`},shortName:`MACD`,inputs:{source:{source:!0},fast:{kind:`int`,min:1},slow:{kind:`int`,min:1},signal:{kind:`int`,min:1}},plots:[{key:`histogram`,title:`Histogram`,color:2,kind:`histogram`,tone:`sign`,downColor:3},{key:`macd`,title:`MACD`,color:0},{key:`signal`,title:`Signal`,color:1}]};emas=new WeakMap;workerState(e){return this.emas.get(e)}adoptWorkerState(e,t){t&&this.emas.set(e,t)}calculate(e,t){let n=H(t,`fast`,12,1),r=H(t,`slow`,26,1),i=H(t,`signal`,9,1),a=new L,o=Array(e.length).fill(null),s={values:a,series:o};if(e.length<r)return s;let c=2/(n+1),l=2/(r+1),u=2/(i+1),d=Array(e.length),f=Array(e.length),p=e[0].close,m=e[0].close,h=0,g=!1;for(let t=0;t<e.length;t++){let n=e[t].close;if(t===0?(p=n,m=n):(p=(n-p)*c+p,m=(n-m)*l+m),d[t]=p,f[t]=m,t>=r-1){let n=p-m;g?h=(n-h)*u+h:(h=n,g=!0);let r=n-h,i={macd:n,signal:h,histogram:r};a.set(e[t].time,i),o[t]=i}}return this.emas.set(s,{fast:d,slow:f}),s}update(e,t,n,r){let i=H(t,`fast`,12,1),a=H(t,`slow`,26,1),o=H(t,`signal`,9,1),s=this.emas.get(n);if(!s||r<a||!this.canResume(e,n,r))return null;let c=s.fast[r-1],l=s.slow[r-1],u=n.series[r-1]?.signal;if(c===void 0||l===void 0||u===void 0)return null;let d=2/(i+1),f=2/(a+1),p=2/(o+1);for(let t=r;t<e.length;t++){let r=e[t].close;c=(r-c)*d+c,l=(r-l)*f+l,s.fast[t]=c,s.slow[t]=l;let i=c-l;u=(i-u)*p+u,this.writePoint(n,e,t,{macd:i,signal:u,histogram:i-u})}return n}},Ss=class extends I{descriptor={id:`stochastic`,name:`Stochastic Oscillator`,placement:`panel`,defaultConfig:{kPeriod:14,dPeriod:3,smooth:3},inputs:{kPeriod:{kind:`int`,min:1},dPeriod:{kind:`int`,min:1},smooth:{kind:`int`,min:1}},shortName:`Stoch`,plots:[{key:`k`,title:`%K`,color:0},{key:`d`,title:`%D`,color:1}],scale:{min:0,max:100},levels:[20,80]};calculate(e,t){let n=H(t,`kPeriod`,14,1),r=H(t,`dPeriod`,3,1),i=H(t,`smooth`,3,1),a=new L,o=Array(e.length).fill(null);if(e.length<n)return{values:a,series:o};let s=[];for(let t=0;t<e.length;t++){if(t<n-1){s.push(0);continue}let r=-1/0,i=1/0;for(let a=t-n+1;a<=t;a++)e[a].high>r&&(r=e[a].high),e[a].low<i&&(i=e[a].low);s.push(r===i?50:(e[t].close-i)/(r-i)*100)}let c=[];for(let e=0;e<s.length;e++){if(e<n-1+i-1){c.push(0);continue}let t=0;for(let n=e-i+1;n<=e;n++)t+=s[n];c.push(t/i)}let l=n-1+i-1;for(let t=l;t<c.length;t++){let n={k:c[t]};if(t>=l+r-1){let e=0;for(let n=t-r+1;n<=t;n++)e+=c[n];n.d=e/r}a.set(e[t].time,n),o[t]=n}return{values:a,series:o}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=H(t,`kPeriod`,14,1),a=H(t,`dPeriod`,3,1),o=H(t,`smooth`,3,1),s=i-1+o-1,c=t=>{let n=-1/0,r=1/0;for(let a=t-i+1;a<=t;a++)e[a].high>n&&(n=e[a].high),e[a].low<r&&(r=e[a].low);return n===r?50:(e[t].close-r)/(n-r)*100},l=e=>{let t=0;for(let n=e-o+1;n<=e;n++)t+=c(n);return t/o};for(let t=r;t<e.length;t++){if(t<s||e.length<i){this.writePoint(n,e,t,null);continue}let r={k:l(t)};if(t>=s+a-1){let e=0;for(let n=t-a+1;n<=t;n++)e+=l(n);r.d=e/a}this.writePoint(n,e,t,r)}return n}},Cs=class extends I{descriptor={id:`atr`,name:`Average True Range`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`ATR`,plots:[{key:`value`,title:`ATR`,color:0}]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null);if(e.length<Math.max(2,n))return{values:r,series:i};let a=[e[0].high-e[0].low];for(let t=1;t<e.length;t++){let n=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a.push(n)}let o=0;for(let e=0;e<n;e++)o+=a[e];o/=n;let s={value:o};r.set(e[n-1].time,s),i[n-1]=s;for(let t=n;t<e.length;t++){o=(o*(n-1)+a[t])/n;let s={value:o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}update(e,t,n,r){let i=H(t,`period`,14,1);if(r<i||!this.canResume(e,n,r))return null;let a=n.series[r-1]?.value;if(a===void 0)return null;for(let t=r;t<e.length;t++){let r=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a=(a*(i-1)+r)/i,this.writePoint(n,e,t,{value:a})}return n}},ws=class extends I{descriptor={id:`adx`,name:`Average Directional Index`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`ADX`,plots:[{key:`adx`,title:`ADX`,color:0},{key:`plusDI`,title:`+DI`,color:1},{key:`minusDI`,title:`−DI`,color:2}],scale:{min:0}};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null);if(e.length<n*2)return{values:r,series:i};let a=[],o=[],s=[];for(let t=1;t<e.length;t++){let n=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a.push(n);let r=e[t].high-e[t-1].high,i=e[t-1].low-e[t].low;o.push(r>i&&r>0?r:0),s.push(i>r&&i>0?i:0)}let c=0,l=0,u=0;for(let e=0;e<n;e++)c+=a[e],l+=o[e],u+=s[e];let d=[];for(let t=n;t<a.length;t++){t>n&&(c=c-c/n+a[t],l=l-l/n+o[t],u=u-u/n+s[t]);let f=c===0?0:l/c*100,p=c===0?0:u/c*100,m=f+p,h=m===0?0:Math.abs(f-p)/m*100;d.push(h);let g=t+1,_={plusDI:f,minusDI:p,dx:h};r.set(e[g].time,_),i[g]=_}if(d.length>=n){let t=0;for(let e=0;e<n;e++)t+=d[e];t/=n;let a=n*2;if(a<e.length){let n=r.get(e[a].time);n&&(n.adx=t),i[a]&&(i[a].adx=t)}for(let a=n;a<d.length;a++){t=(t*(n-1)+d[a])/n;let o=a+n+1;if(o<e.length){let n=r.get(e[o].time);n&&(n.adx=t),i[o]&&(i[o].adx=t)}}}return{values:r,series:i}}},Ts=class extends I{descriptor={id:`obv`,name:`On Balance Volume`,placement:`panel`,defaultConfig:{},shortName:`OBV`,plots:[{key:`value`,title:`OBV`,color:0}]};calculate(e,t){let n=new L,r=Array(e.length).fill(null);if(e.length===0)return{values:n,series:r};let i=0,a={value:i};n.set(e[0].time,a),r[0]=a;for(let t=1;t<e.length;t++){e[t].close>e[t-1].close?i+=e[t].volume:e[t].close<e[t-1].close&&(i-=e[t].volume);let a={value:i};n.set(e[t].time,a),r[t]=a}return{values:n,series:r}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=n.series[r-1]?.value;if(i===void 0)return null;for(let t=r;t<e.length;t++)e[t].close>e[t-1].close?i+=e[t].volume:e[t].close<e[t-1].close&&(i-=e[t].volume),this.writePoint(n,e,t,{value:i});return n}},Es=class extends I{descriptor={id:`williamsR`,name:`Williams %R`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`%R`,plots:[{key:`value`,title:`%R`,color:0}],scale:{min:-100,max:0},levels:[-80,-20]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s={value:a===o?-50:(a-e[t].close)/(a-o)*-100};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}},Ds=class extends I{descriptor={id:`cci`,name:`Commodity Channel Index`,placement:`panel`,defaultConfig:{period:20},inputs:{period:{kind:`int`,min:1}},shortName:`CCI`,plots:[{key:`value`,title:`CCI`,color:0}],levels:[-100,0,100]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0;for(let r=t-n+1;r<=t;r++)a+=(e[r].high+e[r].low+e[r].close)/3;let o=a/n,s=0;for(let r=t-n+1;r<=t;r++){let t=(e[r].high+e[r].low+e[r].close)/3;s+=Math.abs(t-o)}let c=s/n,l=(e[t].high+e[t].low+e[t].close)/3,u={value:c===0?0:(l-o)/(.015*c)};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}},Os=class extends I{descriptor={id:`mfi`,name:`Money Flow Index`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`MFI`,plots:[{key:`value`,title:`MFI`,color:0}],scale:{min:0,max:100},levels:[20,80]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null);if(e.length<n+1)return{values:r,series:i};let a=e.map(e=>(e.high+e.low+e.close)/3),o=a.map((t,n)=>t*e[n].volume);for(let t=n;t<e.length;t++){let s=0,c=0;for(let e=t-n+1;e<=t;e++)a[e]>a[e-1]?s+=o[e]:a[e]<a[e-1]&&(c+=o[e]);let l={value:c===0?100:100-100/(1+s/c)};r.set(e[t].time,l),i[t]=l}return{values:r,series:i}}},ks=class extends I{descriptor={id:`aroon`,name:`Aroon`,placement:`panel`,defaultConfig:{period:25},inputs:{period:{kind:`int`,min:1}},shortName:`Aroon`,plots:[{key:`up`,title:`Up`,color:0},{key:`down`,title:`Down`,color:1}],scale:{min:0,max:100}};calculate(e,t){let n=H(t,`period`,25,1),r=new L,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=0,o=0,s=-1/0,c=1/0;for(let r=0;r<=n;r++){let i=t-n+r;e[i].high>s&&(s=e[i].high,a=r),e[i].low<c&&(c=e[i].low,o=r)}let l={up:a/n*100,down:o/n*100};r.set(e[t].time,l),i[t]=l}return{values:r,series:i}}},As=class extends I{descriptor={id:`roc`,name:`Rate of Change`,placement:`panel`,defaultConfig:{period:12,source:`close`},shortName:`ROC`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`ROC`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`period`,12,1),r=new L,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=e[t-n].close,o={value:a===0?0:(e[t].close-a)/a*100};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}},js=class extends I{descriptor={id:`tsi`,name:`True Strength Index`,placement:`panel`,defaultConfig:{longPeriod:25,shortPeriod:13,signalPeriod:7,source:`close`},shortName:`TSI`,inputs:{source:{source:!0},longPeriod:{kind:`int`,min:1},shortPeriod:{kind:`int`,min:1},signalPeriod:{kind:`int`,min:1}},plots:[{key:`tsi`,title:`TSI`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};emaSmooth(e,t){let n=2/(t+1),r=[e[0]];for(let t=1;t<e.length;t++)r.push((e[t]-r[t-1])*n+r[t-1]);return r}calculate(e,t){let n=H(t,`longPeriod`,25,1),r=H(t,`shortPeriod`,13,1),i=H(t,`signalPeriod`,7,1),a=new L,o=Array(e.length).fill(null);if(e.length<2)return{values:a,series:o};let s=[],c=[];for(let t=1;t<e.length;t++){let n=e[t].close-e[t-1].close;s.push(n),c.push(Math.abs(n))}let l=this.emaSmooth(this.emaSmooth(s,n),r),u=this.emaSmooth(this.emaSmooth(c,n),r),d=[];for(let e=0;e<l.length;e++)d.push(u[e]===0?0:l[e]/u[e]*100);let f=this.emaSmooth(d,i);for(let t=0;t<d.length;t++){let n=t+1;if(n<e.length){let r={tsi:d[t],signal:f[t]};a.set(e[n].time,r),o[n]=r}}return{values:a,series:o}}},Ms=class extends I{descriptor={id:`cmf`,name:`Chaikin Money Flow`,placement:`panel`,defaultConfig:{period:20},inputs:{period:{kind:`int`,min:1}},shortName:`CMF`,plots:[{key:`value`,title:`CMF`,color:0,kind:`histogram`,tone:`sign`,downColor:1}]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0,o=0;for(let r=t-n+1;r<=t;r++){let t=e[r].high-e[r].low,n=t===0?0:(e[r].close-e[r].low-(e[r].high-e[r].close))/t;a+=n*e[r].volume,o+=e[r].volume}let s={value:o===0?0:a/o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}},Ns=class extends I{descriptor={id:`voldelta`,name:`Volume Delta`,placement:`panel`,defaultConfig:{mode:0},inputs:{mode:{kind:`int`,min:0,max:1}},shortName:`Vol Δ`,plots:[{key:`value`,title:`Delta`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}]};calculate(e,t){let n=V(t,`mode`,0)>=1,r=new L,i=Array(e.length).fill(null),a=0;for(let t=0;t<e.length;t++){let o=e[t],s=o.close>=o.open,c=s?o.volume:-o.volume;a+=c;let l={value:n?a:c,up:+!!s};r.set(o.time,l),i[t]=l}return{values:r,series:i}}},Ps=class extends I{descriptor={id:`vortex`,name:`Vortex Indicator`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`VI`,plots:[{key:`viPlus`,title:`VI+`,color:0},{key:`viMinus`,title:`VI−`,color:1}],levels:[1]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};let a=Array(e.length).fill(0),o=Array(e.length).fill(0),s=Array(e.length).fill(0);for(let t=1;t<e.length;t++){a[t]=Math.abs(e[t].high-e[t-1].low),o[t]=Math.abs(e[t].low-e[t-1].high);let n=e[t].high,r=e[t].low,i=e[t-1].close;s[t]=Math.max(n-r,Math.abs(n-i),Math.abs(r-i))}let c=0,l=0,u=0;for(let t=1;t<e.length;t++)if(c+=a[t],l+=o[t],u+=s[t],t>n&&(c-=a[t-n],l-=o[t-n],u-=s[t-n]),t>=n&&u>0){let n={viPlus:c/u,viMinus:l/u};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}},Fs=class extends I{descriptor={id:`chop`,name:`Choppiness Index`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:2}},shortName:`CHOP`,plots:[{key:`value`,title:`CHOP`,color:0}],scale:{min:0,max:100},levels:[38.2,61.8]};calculate(e,t){let n=H(t,`period`,14,2),r=new L,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};let a=Array(e.length).fill(0);for(let t=1;t<e.length;t++){let n=e[t].high,r=e[t].low,i=e[t-1].close;a[t]=Math.max(n-r,Math.abs(n-i),Math.abs(r-i))}let o=Math.log10(n),s=0;for(let t=1;t<e.length;t++)if(s+=a[t],t>n&&(s-=a[t-n]),t>=n){let a=-1/0,c=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<c&&(c=e[r].low);let l=a-c;if(l>0&&s>0){let n={value:Math.max(0,Math.min(100,100*Math.log10(s/l)/o))};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}},Is=class extends I{descriptor={id:`uo`,name:`Ultimate Oscillator`,placement:`panel`,defaultConfig:{fast:7,mid:14,slow:28},inputs:{fast:{kind:`int`,min:1},mid:{kind:`int`,min:1},slow:{kind:`int`,min:1}},shortName:`UO`,plots:[{key:`value`,title:`UO`,color:0}],scale:{min:0,max:100},levels:[30,70]};calculate(e,t){let n=H(t,`fast`,7,1),r=H(t,`mid`,14,1),i=H(t,`slow`,28,1),a=new L,o=Array(e.length).fill(null);if(e.length<=i)return{values:a,series:o};let s=Array(e.length).fill(0),c=Array(e.length).fill(0);for(let t=1;t<e.length;t++){let n=e[t-1].close,r=Math.min(e[t].low,n),i=Math.max(e[t].high,n);s[t]=e[t].close-r,c[t]=i-r}let l=(e,t,n)=>{let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i];return r};for(let t=i;t<e.length;t++){let u=Ls(l(s,t,n),l(c,t,n)),d=Ls(l(s,t,r),l(c,t,r)),f=Ls(l(s,t,i),l(c,t,i)),p={value:100*(4*u+2*d+f)/7};a.set(e[t].time,p),o[t]=p}return{values:a,series:o}}};function Ls(e,t){return t===0?0:e/t}var Rs=class extends I{descriptor={id:`fi`,name:`Force Index`,placement:`panel`,defaultConfig:{period:13},inputs:{period:{kind:`int`,min:1}},shortName:`EFI`,plots:[{key:`value`,title:`EFI`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`period`,13,1),r=new L,i=Array(e.length).fill(null);if(e.length<2)return{values:r,series:i};let a=2/(n+1),o;for(let t=1;t<e.length;t++){let s=(e[t].close-e[t-1].close)*e[t].volume;if(o=o===void 0?s:s*a+o*(1-a),t>=n){let n={value:o};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}},zs=class extends I{descriptor={id:`crsi`,name:`Connors RSI`,placement:`panel`,defaultConfig:{rsiPeriod:3,streakPeriod:2,rankPeriod:100,source:`close`},shortName:`CRSI`,inputs:{source:{source:!0},rsiPeriod:{kind:`int`,min:1},streakPeriod:{kind:`int`,min:1},rankPeriod:{kind:`int`,min:1}},plots:[{key:`value`,title:`CRSI`,color:0}],scale:{min:0,max:100},levels:[10,90]};calculate(e,t){let n=H(t,`rsiPeriod`,3,1),r=H(t,`streakPeriod`,2,1),i=H(t,`rankPeriod`,100,1),a=new L,o=Array(e.length).fill(null),s=e.length;if(s<2)return{values:a,series:o};let c=e.map(e=>e.close),l=Bs(c,n),u=Array(s).fill(0);for(let e=1;e<s;e++)c[e]>c[e-1]?u[e]=u[e-1]>0?u[e-1]+1:1:c[e]<c[e-1]?u[e]=u[e-1]<0?u[e-1]-1:-1:u[e]=0;let d=Bs(u,r),f=Array(s).fill(0);for(let e=1;e<s;e++)f[e]=c[e-1]===0?0:(c[e]-c[e-1])/c[e-1]*100;for(let t=0;t<s;t++){if(t<i+1)continue;let n=l[t],r=d[t];if(n===void 0||r===void 0)continue;let s=0;for(let e=t-i;e<t;e++)f[e]<f[t]&&s++;let c=s/i*100,u={value:(n+r+c)/3};a.set(e[t].time,u),o[t]=u}return{values:a,series:o}}};function Bs(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<=t)return r;let i=0,a=0;for(let n=1;n<=t;n++){let t=e[n]-e[n-1];t>=0?i+=t:a-=t}i/=t,a/=t,r[t]=a===0?100:100-100/(1+i/a);for(let o=t+1;o<n;o++){let n=e[o]-e[o-1],s=n>0?n:0,c=n<0?-n:0;i=(i*(t-1)+s)/t,a=(a*(t-1)+c)/t,r[o]=a===0?100:100-100/(1+i/a)}return r}var Vs=class extends I{descriptor={id:`coppock`,name:`Coppock Curve`,placement:`panel`,defaultConfig:{longRoc:14,shortRoc:11,wma:10,source:`close`},shortName:`Coppock`,inputs:{source:{source:!0},longRoc:{kind:`int`,min:1},shortRoc:{kind:`int`,min:1},wma:{kind:`int`,min:1}},plots:[{key:`value`,title:`Coppock`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`longRoc`,14,1),r=H(t,`shortRoc`,11,1),i=H(t,`wma`,10,1),a=new L,o=Array(e.length).fill(null),s=e.length,c=Math.max(n,r);if(s<=c+i)return{values:a,series:o};let l=e.map(e=>e.close),u=(e,t)=>l[e-t]===0?0:(l[e]-l[e-t])/l[e-t]*100,d=Array(s).fill(void 0);for(let e=c;e<s;e++)d[e]=u(e,n)+u(e,r);let f=i*(i+1)/2;for(let t=c+i-1;t<s;t++){let n=0,r=!0;for(let e=0;e<i;e++){let a=d[t-e];if(a===void 0){r=!1;break}n+=a*(i-e)}if(!r)continue;let s={value:n/f};a.set(e[t].time,s),o[t]=s}return{values:a,series:o}}},Hs=class extends I{descriptor={id:`kst`,name:`Know Sure Thing`,placement:`panel`,defaultConfig:{roc1:10,roc2:15,roc3:20,roc4:30,sma1:10,sma2:10,sma3:10,sma4:15,signal:9,source:`close`},shortName:`KST`,inputs:{source:{source:!0},roc1:{kind:`int`,min:1},roc2:{kind:`int`,min:1},roc3:{kind:`int`,min:1},roc4:{kind:`int`,min:1},sma1:{kind:`int`,min:1},sma2:{kind:`int`,min:1},sma3:{kind:`int`,min:1},sma4:{kind:`int`,min:1},signal:{kind:`int`,min:1}},plots:[{key:`value`,title:`KST`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=H(t,`roc1`,10,1),r=H(t,`roc2`,15,1),i=H(t,`roc3`,20,1),a=H(t,`roc4`,30,1),o=H(t,`sma1`,10,1),s=H(t,`sma2`,10,1),c=H(t,`sma3`,10,1),l=H(t,`sma4`,15,1),u=H(t,`signal`,9,1),d=new L,f=Array(e.length).fill(null),p=e.length;if(p<2)return{values:d,series:f};let m=e.map(e=>e.close),h=Ws(Us(m,n),o),g=Ws(Us(m,r),s),_=Ws(Us(m,i),c),v=Ws(Us(m,a),l),y=Array(p).fill(void 0);for(let e=0;e<p;e++)h[e]===void 0||g[e]===void 0||_[e]===void 0||v[e]===void 0||(y[e]=h[e]*1+g[e]*2+_[e]*3+v[e]*4);let b=Ws(y,u);for(let t=0;t<p;t++){if(y[t]===void 0)continue;let n={value:y[t]};b[t]!==void 0&&(n.signal=b[t]),d.set(e[t].time,n),f[t]=n}return{values:d,series:f}}};function Us(e,t){let n=Array(e.length).fill(void 0);for(let r=t;r<e.length;r++)n[r]=e[r-t]===0?0:(e[r]-e[r-t])/e[r-t]*100;return n}function Ws(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=!0;for(let n=r-t+1;n<=r;n++){let t=e[n];if(t===void 0){a=!1;break}i+=t}a&&(n[r]=i/t)}return n}var Gs=class extends I{descriptor={id:`elderray`,name:`Elder Ray`,placement:`panel`,defaultConfig:{period:13},inputs:{period:{kind:`int`,min:1}},shortName:`Elder Ray`,plots:[{key:`bull`,title:`Bull`,color:0,kind:`histogram`},{key:`bear`,title:`Bear`,color:1,kind:`histogram`}]};calculate(e,t){let n=H(t,`period`,13,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a===0)return{values:r,series:i};let o=2/(n+1),s;for(let t=0;t<a;t++)if(s=s===void 0?e[t].close:e[t].close*o+s*(1-o),t>=n-1){let n={bull:e[t].high-s,bear:e[t].low-s};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(t,n,r,i){let a=n.series;if(!a)return;let o=Math.max(0,r.visibleRange.from),s=Math.min(r.visibleRange.to,a.length-1),c=e.E(r),l=c(0),u=Math.max(1,r.barWidth/2),d=[[`bull`,i.colors[0],-u],[`bear`,i.colors[1]??i.colors[0],0]];for(let[n,f,p]of d)if(i.plots?.[n]?.visible!==!1){t.beginPath(),t.fillStyle=f;for(let i=o;i<=s;i++){let o=a[i]?.[n];if(o===void 0||!Number.isFinite(o))continue;let s=c(o);t.rect(e.b(i,r)+p,Math.min(s,l),u,Math.max(1,Math.abs(s-l)))}t.fill()}}},Ks=class extends I{descriptor={id:`stc`,name:`Schaff Trend Cycle`,placement:`panel`,defaultConfig:{fast:23,slow:50,cycle:10,source:`close`},shortName:`STC`,inputs:{source:{source:!0},fast:{kind:`int`,min:1},slow:{kind:`int`,min:1},cycle:{kind:`int`,min:1}},plots:[{key:`value`,title:`STC`,color:0}],scale:{min:0,max:100},levels:[25,75]};calculate(e,t){let n=H(t,`fast`,23,1),r=H(t,`slow`,50,1),i=H(t,`cycle`,10,1),a=new L,o=Array(e.length).fill(null),s=e.length;if(s===0)return{values:a,series:o};let c=e.map(e=>e.close),l=2/(n+1),u=2/(r+1),d=c[0],f=c[0],p=Array(s);for(let e=0;e<s;e++)d=e===0?c[0]:c[e]*l+d*(1-l),f=e===0?c[0]:c[e]*u+f*(1-u),p[e]=d-f;let m=qs(qs(p,i),i);for(let t=0;t<s;t++){let n=m[t];if(n===void 0)continue;let r={value:Math.max(0,Math.min(100,n))};a.set(e[t].time,r),o[t]=r}return{values:a,series:o}}};function qs(e,t){let n=e.length,r=Array(n).fill(void 0),i;for(let a=0;a<n;a++){if(a<t-1)continue;let n=1/0,o=-1/0,s=!0;for(let r=a-t+1;r<=a;r++){let t=e[r];if(t===void 0){s=!1;break}t<n&&(n=t),t>o&&(o=t)}if(!s||e[a]===void 0)continue;let c=o-n>0?(e[a]-n)/(o-n)*100:50;i=i===void 0?c:i+.5*(c-i),r[a]=i}return r}var Js=class extends I{descriptor={id:`kvo`,name:`Klinger Oscillator`,placement:`panel`,defaultConfig:{fast:34,slow:55,signal:13},inputs:{fast:{kind:`int`,min:1},slow:{kind:`int`,min:1},signal:{kind:`int`,min:1}},shortName:`KVO`,plots:[{key:`value`,title:`KVO`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=H(t,`fast`,34,1),r=H(t,`slow`,55,1),i=H(t,`signal`,13,1),a=new L,o=Array(e.length).fill(null),s=e.length;if(s<2)return{values:a,series:o};let c=2/(n+1),l=2/(r+1),u=2/(i+1),d,f=1,p=0,m=0,h,g,_;for(let t=0;t<s;t++){let n=e[t],i=n.high+n.low+n.close,s=d===void 0||i>d?1:-1,v=n.high-n.low;m=d===void 0?v:s===f?m+v:p+v;let y=m===0?0:n.volume*Math.abs(2*(v/m-1))*s*100;h=h===void 0?y:y*c+h*(1-c),g=g===void 0?y:y*l+g*(1-l);let b=h-g;if(_=_===void 0?b:b*u+_*(1-u),d=i,f=s,p=v,t>=r){let e={value:b,signal:_};a.set(n.time,e),o[t]=e}}return{values:a,series:o}}},Ys=class extends I{descriptor={id:`fisher`,name:`Fisher Transform`,placement:`panel`,defaultConfig:{period:9},inputs:{period:{kind:`int`,min:1}},shortName:`Fisher`,plots:[{key:`value`,title:`Fisher`,color:0},{key:`trigger`,title:`Trigger`,color:1}],levels:[0]};calculate(e,t){let n=H(t,`period`,9,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=e.map(e=>(e.high+e.low)/2),s=0,c=0;for(let t=n-1;t<a;t++){let a=-1/0,l=1/0;for(let e=t-n+1;e<=t;e++)o[e]>a&&(a=o[e]),o[e]<l&&(l=o[e]);s=.33*(a-l>0?2*(o[t]-l)/(a-l)-1:0)+.67*s,s=Math.max(-.999,Math.min(.999,s));let u=c;c=.5*Math.log((1+s)/(1-s))+.5*c;let d={value:c,trigger:u};r.set(e[t].time,d),i[t]=d}return{values:r,series:i}}},Xs=class extends I{descriptor={id:`dpo`,name:`Detrended Price Oscillator`,placement:`panel`,defaultConfig:{period:20,source:`close`},shortName:`DPO`,inputs:{source:{source:!0},period:{kind:`int`,min:2}},plots:[{key:`value`,title:`DPO`,color:0,kind:`histogram`,tone:`sign`,downColor:1}]};calculate(e,t){let n=H(t,`period`,20,2),r=Math.floor(n/2)+1,i=new L,a=Array(e.length).fill(null),o=e.length;if(o<n)return{values:i,series:a};let s=0;for(let t=0;t<o;t++)if(s+=e[t].close,t>=n&&(s-=e[t-n].close),t>=n-1&&t-r>=0){let o=s/n,c={value:e[t-r].close-o};i.set(e[t].time,c),a[t]=c}return{values:i,series:a}}},Zs=class extends I{descriptor={id:`bop`,name:`Balance of Power`,placement:`panel`,defaultConfig:{smooth:14},inputs:{smooth:{kind:`int`,min:1}},shortName:`BOP`,plots:[{key:`value`,title:`BOP`,color:0}],scale:{min:-1,max:1},levels:[0]};calculate(e,t){let n=H(t,`smooth`,14,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a===0)return{values:r,series:i};let o=Array(a);for(let t=0;t<a;t++){let n=e[t].high-e[t].low;o[t]=n>0?(e[t].close-e[t].open)/n:0}let s=0;for(let t=0;t<a;t++)if(s+=o[t],t>=n&&(s-=o[t-n]),t>=n-1){let a={value:s/n};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}},Qs=class extends I{descriptor={id:`massindex`,name:`Mass Index`,placement:`panel`,defaultConfig:{ema:9,sum:25},inputs:{ema:{kind:`int`,min:1},sum:{kind:`int`,min:1}},shortName:`Mass`,plots:[{key:`value`,title:`Mass`,color:0}],levels:[26.5,27]};calculate(e,t){let n=H(t,`ema`,9,1),r=H(t,`sum`,25,1),i=new L,a=Array(e.length).fill(null),o=e.length;if(o<r)return{values:i,series:a};let s=2/(n+1),c,l,u=Array(o).fill(0);for(let t=0;t<o;t++){let n=e[t].high-e[t].low;c=c===void 0?n:n*s+c*(1-s),l=l===void 0?c:c*s+l*(1-s),u[t]=l===0?1:c/l}let d=0;for(let t=0;t<o;t++)if(d+=u[t],t>=r&&(d-=u[t-r]),t>=n+r){let n={value:d};i.set(e[t].time,n),a[t]=n}return{values:i,series:a}}},$s=class extends I{descriptor={id:`cmo`,name:`Chande Momentum`,placement:`panel`,defaultConfig:{period:9,source:`close`},shortName:`CMO`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`CMO`,color:0}],scale:{min:-100,max:100},levels:[-50,0,50]};calculate(e,t){let n=H(t,`period`,9,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a<=n)return{values:r,series:i};let o=Array(a).fill(0),s=Array(a).fill(0);for(let t=1;t<a;t++){let n=e[t].close-e[t-1].close;o[t]=n>0?n:0,s[t]=n<0?-n:0}let c=0,l=0;for(let t=1;t<a;t++)if(c+=o[t],l+=s[t],t>n&&(c-=o[t-n],l-=s[t-n]),t>=n){let n=c+l,a={value:n>0?100*(c-l)/n:0};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}},ec=class extends I{descriptor={id:`trix`,name:`TRIX`,placement:`panel`,defaultConfig:{period:15,signal:9,source:`close`},shortName:`TRIX`,inputs:{source:{source:!0},period:{kind:`int`,min:1},signal:{kind:`int`,min:1}},plots:[{key:`value`,title:`TRIX`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=H(t,`period`,15,1),r=H(t,`signal`,9,1),i=new L,a=Array(e.length).fill(null),o=e.length;if(o<2)return{values:i,series:a};let s=tc(tc(tc(e.map(e=>e.close),n),n),n),c=Array(o).fill(0);for(let e=1;e<o;e++)c[e]=s[e-1]===0?0:(s[e]-s[e-1])/s[e-1]*100;let l=tc(c,r),u=3*n;for(let t=u;t<o;t++){let n={value:c[t],signal:l[t]};i.set(e[t].time,n),a[t]=n}return{values:i,series:a}}};function tc(e,t){let n=2/(t+1),r=Array(e.length).fill(0),i=e[0]??0;r[0]=i;for(let t=1;t<e.length;t++)i=e[t]*n+i*(1-n),r[t]=i;return r}var nc=class extends I{descriptor={id:`emv`,name:`Ease of Movement`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`EOM`,plots:[{key:`value`,title:`EOM`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a<2)return{values:r,series:i};let o=Array(a).fill(0);for(let t=1;t<a;t++){let n=(e[t].high+e[t].low)/2,r=(e[t-1].high+e[t-1].low)/2,i=e[t].high-e[t].low,a=e[t].volume;o[t]=a>0?(n-r)*i/a:0}let s=0;for(let t=1;t<a;t++)if(s+=o[t],t>n&&(s-=o[t-n]),t>=n){let a={value:s/n};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}},rc=class extends I{descriptor={id:`pvt`,name:`Price Volume Trend`,placement:`panel`,defaultConfig:{},shortName:`PVT`,plots:[{key:`value`,title:`PVT`,color:0}]};calculate(e,t){let n=new L,r=Array(e.length).fill(null),i=e.length;if(i===0)return{values:n,series:r};let a=0;n.set(e[0].time,{value:0}),r[0]={value:0};for(let t=1;t<i;t++){let i=e[t-1].close;i!==0&&(a+=e[t].volume*(e[t].close-i)/i);let o={value:a};n.set(e[t].time,o),r[t]=o}return{values:n,series:r}}},ic=class extends I{descriptor={id:`wad`,name:`Williams A/D`,placement:`panel`,defaultConfig:{},shortName:`WAD`,plots:[{key:`value`,title:`WAD`,color:0}]};calculate(e,t){let n=new L,r=Array(e.length).fill(null),i=e.length;if(i===0)return{values:n,series:r};let a=0;n.set(e[0].time,{value:0}),r[0]={value:0};for(let t=1;t<i;t++){let i=e[t-1].close,o=e[t].close;o>i?a+=o-Math.min(e[t].low,i):o<i&&(a+=o-Math.max(e[t].high,i));let s={value:a};n.set(e[t].time,s),r[t]=s}return{values:n,series:r}}},ac=class extends I{descriptor={id:`chaikinvol`,name:`Chaikin Volatility`,placement:`panel`,defaultConfig:{ema:10,roc:10},inputs:{ema:{kind:`int`,min:1},roc:{kind:`int`,min:1}},shortName:`CV`,plots:[{key:`value`,title:`CV`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`ema`,10,1),r=H(t,`roc`,10,1),i=new L,a=Array(e.length).fill(null),o=e.length;if(o<=r)return{values:i,series:a};let s=2/(n+1),c=Array(o),l=e[0].high-e[0].low;c[0]=l;for(let t=1;t<o;t++)l=(e[t].high-e[t].low)*s+l*(1-s),c[t]=l;for(let t=n+r;t<o;t++){let n=c[t-r],o={value:n===0?0:(c[t]-n)/n*100};i.set(e[t].time,o),a[t]=o}return{values:i,series:a}}},oc=class extends I{descriptor={id:`rvi`,name:`Relative Vigor Index`,placement:`panel`,defaultConfig:{period:10},inputs:{period:{kind:`int`,min:1}},shortName:`RVGI`,plots:[{key:`value`,title:`RVGI`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=H(t,`period`,10,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a<n+3)return{values:r,series:i};let o=Array(a).fill(0),s=Array(a).fill(0);for(let t=0;t<a;t++)o[t]=e[t].close-e[t].open,s[t]=e[t].high-e[t].low;let c=(e,t)=>(e[t]+2*e[t-1]+2*e[t-2]+e[t-3])/6,l=Array(a).fill(void 0),u=Array(a).fill(void 0);for(let e=3;e<a;e++)l[e]=c(o,e),u[e]=c(s,e);let d=Array(a).fill(void 0);for(let e=3+n-1;e<a;e++){let t=0,r=0;for(let i=e-n+1;i<=e;i++)t+=l[i],r+=u[i];d[e]=r===0?0:t/r}for(let t=0;t<a;t++){if(d[t]===void 0)continue;let n={value:d[t]};t>=3&&d[t-3]!==void 0&&(n.signal=(d[t]+2*d[t-1]+2*d[t-2]+d[t-3])/6),r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}},sc=class extends I{descriptor={id:`stochrsi`,name:`Stochastic RSI`,placement:`panel`,defaultConfig:{rsiPeriod:14,stochPeriod:14,k:3,d:3,source:`close`},shortName:`Stoch RSI`,inputs:{source:{source:!0},rsiPeriod:{kind:`int`,min:1},stochPeriod:{kind:`int`,min:1},k:{kind:`int`,min:1},d:{kind:`int`,min:1}},plots:[{key:`k`,title:`%K`,color:0},{key:`d`,title:`%D`,color:1}],scale:{min:0,max:100},levels:[20,80]};calculate(e,t){let n=H(t,`rsiPeriod`,14,1),r=H(t,`stochPeriod`,14,1),i=H(t,`k`,3,1),a=H(t,`d`,3,1),o=new L,s=Array(e.length).fill(null),c=e.length;if(c<=n+r)return{values:o,series:s};let l=cc(e.map(e=>e.close),n),u=Array(c).fill(void 0);for(let e=0;e<c;e++){if(l[e]===void 0)continue;let t=1/0,n=-1/0,i=!0;for(let a=e-r+1;a<=e;a++){if(a<0||l[a]===void 0){i=!1;break}l[a]<t&&(t=l[a]),l[a]>n&&(n=l[a])}i&&(u[e]=n-t>0?(l[e]-t)/(n-t)*100:0)}let d=lc(u,i),f=lc(d,a);for(let t=0;t<c;t++){if(d[t]===void 0)continue;let n={k:d[t]};f[t]!==void 0&&(n.d=f[t]),o.set(e[t].time,n),s[t]=n}return{values:o,series:s}}};function cc(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<=t)return r;let i=0,a=0;for(let n=1;n<=t;n++){let t=e[n]-e[n-1];t>=0?i+=t:a-=t}i/=t,a/=t,r[t]=a===0?100:100-100/(1+i/a);for(let o=t+1;o<n;o++){let n=e[o]-e[o-1];i=(i*(t-1)+(n>0?n:0))/t,a=(a*(t-1)+(n<0?-n:0))/t,r[o]=a===0?100:100-100/(1+i/a)}return r}function lc(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=!0;for(let n=r-t+1;n<=r;n++){if(e[n]===void 0){a=!1;break}i+=e[n]}a&&(n[r]=i/t)}return n}var uc=class extends I{descriptor={id:`ppo`,name:`Percentage Price Oscillator`,placement:`panel`,defaultConfig:{fast:12,slow:26,signal:9,source:`close`},shortName:`PPO`,inputs:{source:{source:!0},fast:{kind:`int`,min:1},slow:{kind:`int`,min:1},signal:{kind:`int`,min:1}},plots:[{key:`hist`,title:`Histogram`,color:2,kind:`histogram`,tone:`sign`,downColor:3},{key:`value`,title:`PPO`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=H(t,`fast`,12,1),r=H(t,`slow`,26,1),i=H(t,`signal`,9,1),a=new L,o=Array(e.length).fill(null),s=e.length;if(s<=r)return{values:a,series:o};let c=e.map(e=>e.close),l=dc(c,n),u=dc(c,r),d=Array(s).fill(void 0);for(let e=0;e<s;e++)l[e]===void 0||u[e]===void 0||u[e]===0||(d[e]=(l[e]-u[e])/u[e]*100);let f=dc(d,i);for(let t=0;t<s;t++){if(d[t]===void 0)continue;let n={value:d[t]};f[t]!==void 0&&(n.signal=f[t],n.hist=d[t]-f[t]),a.set(e[t].time,n),o[t]=n}return{values:a,series:o}}};function dc(e,t){let n=e.length,r=Array(n).fill(void 0),i=2/(t+1),a,o=0,s=0;for(let c=0;c<n;c++){let n=e[c];n!==void 0&&(a===void 0?(o+=n,s++,s===t&&(a=o/t,r[c]=a)):(a=n*i+a*(1-i),r[c]=a))}return r}var fc=class extends I{descriptor={id:`ac`,name:`Accelerator Oscillator`,placement:`panel`,defaultConfig:{},shortName:`AC`,plots:[{key:`value`,title:`AC`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}]};calculate(e){let t=new L,n=Array(e.length).fill(null),r=e.length;if(r<38)return{values:t,series:n};let i=e.map(e=>(e.high+e.low)/2),a=Array(r).fill(void 0);for(let e=33;e<r;e++)a[e]=pc(i,e,5)-pc(i,e,34);let o;for(let i=37;i<r;i++){let r=0;for(let e=i-4;e<=i;e++)r+=a[e];let s=a[i]-r/5,c=o===void 0?s>=0:s>=o;o=s;let l={value:s,up:+!!c};t.set(e[i].time,l),n[i]=l}return{values:t,series:n}}};function pc(e,t,n){let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i];return r/n}var mc=class extends I{descriptor={id:`rmi`,name:`Relative Momentum Index`,placement:`panel`,defaultConfig:{period:20,momentum:5,source:`close`},shortName:`RMI`,inputs:{source:{source:!0},period:{kind:`int`,min:1},momentum:{kind:`int`,min:1}},plots:[{key:`value`,title:`RMI`,color:0}],scale:{min:0,max:100},levels:[30,70]};calculate(e,t){let n=H(t,`period`,20,1),r=H(t,`momentum`,5,1),i=new L,a=Array(e.length).fill(null),o=e.length;if(o<=n+r)return{values:i,series:a};let s=e.map(e=>e.close),c=Array(o).fill(0),l=Array(o).fill(0);for(let e=r;e<o;e++){let t=s[e]-s[e-r];c[e]=t>0?t:0,l[e]=t<0?-t:0}let u=0,d=0,f=r+n;for(let e=r+1;e<=f;e++)u+=c[e],d+=l[e];u/=n,d/=n;let p=t=>{let n={value:d===0?100:100-100/(1+u/d)};i.set(e[t].time,n),a[t]=n};p(f);for(let e=f+1;e<o;e++)u=(u*(n-1)+c[e])/n,d=(d*(n-1)+l[e])/n,p(e);return{values:i,series:a}}},hc=class extends I{descriptor={id:`disparity`,name:`Disparity Index`,placement:`panel`,defaultConfig:{period:14,source:`close`},shortName:`DI`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`DI`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=0;for(let t=0;t<a;t++)if(o+=e[t].close,t>=n&&(o-=e[t-n].close),t>=n-1){let a=o/n,s={value:a===0?0:(e[t].close-a)/a*100};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}},gc=class extends I{descriptor={id:`qstick`,name:`Qstick`,placement:`panel`,defaultConfig:{period:8},inputs:{period:{kind:`int`,min:1}},shortName:`Qstick`,plots:[{key:`value`,title:`Qstick`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`period`,8,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=0;for(let t=0;t<a;t++){let a=e[t].close-e[t].open;if(o+=a,t>=n&&(o-=e[t-n].close-e[t-n].open),t>=n-1){let a={value:o/n};r.set(e[t].time,a),i[t]=a}}return{values:r,series:i}}},_c=class extends I{descriptor={id:`pgo`,name:`Pretty Good Oscillator`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`PGO`,plots:[{key:`value`,title:`PGO`,color:0}],levels:[-3,0,3]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a<=n)return{values:r,series:i};let o=Array(a).fill(0);for(let t=0;t<a;t++){if(t===0){o[t]=e[t].high-e[t].low;continue}let n=e[t-1].close;o[t]=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-n),Math.abs(e[t].low-n))}let s=Array(a).fill(void 0),c=0;for(let e=1;e<=n;e++)c+=o[e];s[n]=c/n;for(let e=n+1;e<a;e++)s[e]=(s[e-1]*(n-1)+o[e])/n;let l=0;for(let t=0;t<a;t++)if(l+=e[t].close,t>=n&&(l-=e[t-n].close),t>=n&&s[t]!==void 0&&s[t]>0){let a=l/n,o={value:(e[t].close-a)/s[t]};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}},vc=class extends I{descriptor={id:`stddev`,name:`Standard Deviation`,placement:`panel`,defaultConfig:{period:20,source:`close`},shortName:`StdDev`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`StdDev`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0;for(let r=t-n+1;r<=t;r++)a+=e[r].close;let o=a/n,s=0;for(let r=t-n+1;r<=t;r++){let t=e[r].close-o;s+=t*t}let c={value:Math.sqrt(s/n)};r.set(e[t].time,c),i[t]=c}return{values:r,series:i}}},yc=.3,bc=.7,xc=class extends I{descriptor={id:`volumeProfile`,name:`Volume Profile`,placement:`overlay`,defaultConfig:{rows:24},inputs:{rows:{kind:`int`,min:1}},shortName:`VP`,plots:[]};calculate(e,t){let n=H(t,`rows`,24,1),r=new L,i=Array(e.length).fill(null);if(e.length===0)return{values:r,series:i};let a=1/0,o=-1/0;for(let t of e)t.low<a&&(a=t.low),t.high>o&&(o=t.high);let s=(o-a||1)/n,c=Array(n).fill(0);for(let t of e){let e=(t.high+t.low+t.close)/3,r=Math.min(n-1,Math.floor((e-a)/s));c[r]+=t.volume}for(let e=0;e<n;e++){let t=a+(e+.5)*s;r.set(e,{price:t,volume:c[e],rowIndex:e})}return{values:r,series:i,meta:{minPrice:a,maxPrice:o,rows:n,rowHeight:s,bins:c,maxVolume:Math.max(...c)}}}render(n,r,i,a){let{chartRect:o}=i,s=r.meta;if(!s||s.maxVolume===0)return;let{minPrice:c,rows:l,rowHeight:u,bins:d,maxVolume:f}=s,p=o.width*yc,m=e.E(i),h=a.colors[0]??t.TC_PALETTE.blue,g=a.colors[1]??t.TC_PALETTE.amber;n.save(),n.globalAlpha=yt(a.opacity);for(let e=0;e<l;e++){let t=d[e]/f*p;if(t<=0)continue;let r=m(c+e*u),i=m(c+(e+1)*u);n.fillStyle=d[e]>f*bc?g:h,n.fillRect(o.x,Math.min(r,i),t,Math.max(Math.abs(r-i)-1,1))}n.restore()}},Sc=class extends I{descriptor={id:`ad`,name:`Accumulation/Distribution`,placement:`panel`,defaultConfig:{},shortName:`A/D`,plots:[{key:`value`,title:`A/D`,color:0}]};calculate(e,t){let n=new L,r=Array(e.length).fill(null);if(e.length===0)return{values:n,series:r};let i=0;for(let t=0;t<e.length;t++){let a=e[t].high-e[t].low,o=a===0?0:(e[t].close-e[t].low-(e[t].high-e[t].close))/a;i+=o*e[t].volume;let s={value:i};n.set(e[t].time,s),r[t]=s}return{values:n,series:r}}},Cc=class extends I{descriptor={id:`vroc`,name:`Volume Rate of Change`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`VROC`,plots:[{key:`value`,title:`VROC`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=e[t-n].volume,o={value:a===0?0:(e[t].volume-a)/a*100};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}},wc=class extends I{descriptor={id:`dema`,name:`Double Exponential Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`DEMA`,inputs:{period:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`value`,title:`DEMA`,color:0}]};emas=new WeakMap;workerState(e){return this.emas.get(e)}adoptWorkerState(e,t){t&&this.emas.set(e,t)}calculate(e,t){let n=H(t,`period`,20,1),r=z(Fa(e),n),i=z(r,n),a=R(e,Wa(r.map((e,t)=>e!==void 0&&i[t]!==void 0?2*e-i[t]:void 0)));return this.emas.set(a,{e1:r,e2:i}),a}update(e,t,n,r){let i=this.emas.get(n);if(!i||!this.canResume(e,n,r))return null;let a=i.e1[r-1],o=i.e2[r-1];if(a===void 0||o===void 0)return null;let s=2/(H(t,`period`,20,1)+1);for(let t=r;t<e.length;t++)a+=s*(e[t].close-a),o+=s*(a-o),i.e1[t]=a,i.e2[t]=o,this.writePoint(n,e,t,{value:2*a-o});return n}},Tc=class extends I{descriptor={id:`smma`,name:`Smoothed Moving Average`,placement:`overlay`,defaultConfig:{period:14,source:`close`},shortName:`SMMA`,inputs:{period:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`value`,title:`SMMA`,color:0}]};calculate(e,t){return R(e,Wa(za(Fa(e),H(t,`period`,14,1))))}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=n.series[r-1]?.value;if(i===void 0)return null;let a=H(t,`period`,14,1);for(let t=r;t<e.length;t++)i+=(e[t].close-i)/a,this.writePoint(n,e,t,{value:i});return n}},Ec=class extends B{descriptor={id:`alma`,name:`Arnaud Legoux Moving Average`,placement:`overlay`,defaultConfig:{period:9,offset:.85,sigma:6,source:`close`},shortName:`ALMA`,inputs:{period:{kind:`int`,min:1,max:5e3},offset:{kind:`number`,min:0,max:1,step:.05},sigma:{kind:`number`,min:.5,step:.5},source:{source:!0}},plots:[{key:`value`,title:`ALMA`,color:0}]};read(e){let t=Math.min(5e3,H(e,`period`,9,1)),n=Math.min(1,Math.max(0,V(e,`offset`,.85))),r=Math.max(.5,V(e,`sigma`,6)),i=n*(t-1),a=t/r,o=Array.from({length:t},(e,t)=>Math.exp(-((t-i)**2)/(2*a*a)));return{period:t,weights:o,norm:o.reduce((e,t)=>e+t,0)}}pointAt(e,t,{period:n,weights:r,norm:i}){if(t<n-1)return null;let a=0;for(let i=0;i<n;i++)a+=r[i]*e[t-n+1+i].close;return{value:a/i}}},Dc=class extends I{descriptor={id:`kama`,name:`Kaufman Adaptive Moving Average`,placement:`overlay`,defaultConfig:{period:10,fast:2,slow:30,source:`close`},shortName:`KAMA`,inputs:{period:{kind:`int`,min:1},fast:{kind:`int`,min:1},slow:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`value`,title:`KAMA`,color:0}]};calculate(e,t){let n=R(e,Array(e.length).fill(null)),r=H(t,`period`,10,1);return e.length<=r||this.extend(e,t,n,r,e[r-1].close),n}update(e,t,n,r){if(r<=H(t,`period`,10,1)||!this.canResume(e,n,r))return null;let i=n.series[r-1]?.value;return i===void 0?null:(this.extend(e,t,n,r,i),n)}extend(e,t,n,r,i){let a=H(t,`period`,10,1),o=2/(H(t,`fast`,2,1)+1),s=2/(H(t,`slow`,30,1)+1);for(let t=r;t<e.length;t++){let r=0;for(let n=t-a+1;n<=t;n++)r+=Math.abs(e[n].close-e[n-1].close);let c=Math.abs(e[t].close-e[t-a].close),l=((r>0?c/r:0)*(o-s)+s)**2;i+=l*(e[t].close-i),this.writePoint(n,e,t,{value:i})}}},Oc=class extends B{descriptor={id:`lsma`,name:`Least Squares Moving Average`,placement:`overlay`,defaultConfig:{period:25,offset:0,source:`close`},shortName:`LSMA`,inputs:{period:{kind:`int`,min:2,max:5e3},offset:{kind:`int`,step:1},source:{source:!0}},plots:[{key:`value`,title:`LSMA`,color:0}]};read(e){let t=Math.min(5e3,H(e,`period`,25,2)),n=Math.round(H(e,`offset`,0,-1e3)),r=t*(t-1)/2;return{period:t,offset:n,sx:r,denom:t*((t-1)*t*(2*t-1)/6)-r*r}}pointAt(e,t,{period:n,offset:r,sx:i,denom:a}){if(t<n-1)return null;let o=0,s=0;for(let r=0;r<n;r++){let i=e[t-n+1+r].close;o+=i,s+=r*i}let c=(n*s-i*o)/a;return{value:(o-c*i)/n+c*(n-1-r)}}},kc=class extends I{descriptor={id:`mcginley`,name:`McGinley Dynamic`,placement:`overlay`,defaultConfig:{period:14,source:`close`},shortName:`McGinley`,inputs:{period:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`value`,title:`McGinley`,color:0}]};calculate(e,t){let n=H(t,`period`,14,1),r=z(Fa(e),n),i=Array(e.length).fill(void 0),a;for(let t=0;t<e.length;t++)a=a===void 0?r[t]:Ac(a,e[t].close,n),i[t]=a;return R(e,Wa(i))}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=n.series[r-1]?.value;if(i===void 0)return null;let a=H(t,`period`,14,1);for(let t=r;t<e.length;t++)i=Ac(i,e[t].close,a),this.writePoint(n,e,t,{value:i});return n}};function Ac(e,t,n){return e>0&&t>0?e+(t-e)/(n*(t/e)**4):t}function jc(e){return e.params.type===`ema`?[`ema`,`ema`]:e.params.type===`sma-ema`?[`sma`,`ema`]:[`sma`,`sma`]}var Mc=class extends I{descriptor={id:`macross`,name:`MA Cross`,placement:`overlay`,defaultConfig:{fast:9,slow:21,type:`sma`,source:`close`},shortName:`MA Cross`,inputs:{fast:{kind:`int`,min:1},slow:{kind:`int`,min:1},type:{options:[`sma`,`ema`,`sma-ema`]},source:{source:!0}},plots:[{key:`fast`,title:`Fast`,color:0},{key:`slow`,title:`Slow`,color:1}]};calculate(e,t){let[n,r]=jc(t),i=Fa(e),a=(t,n)=>t===`ema`?z(i,n):e.map((t,r)=>Ja(e,r,n)),o=a(n,H(t,`fast`,9,1)),s=a(r,H(t,`slow`,21,1));return R(e,o.map((e,t)=>Nc(e,s[t])))}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let[i,a]=jc(t),o=H(t,`fast`,9,1),s=H(t,`slow`,21,1),c=n.series[r-1]?.fast,l=n.series[r-1]?.slow;if(i===`ema`&&c===void 0||a===`ema`&&l===void 0)return null;for(let t=r;t<e.length;t++){let r=e[t].close;c=i===`ema`?c+2/(o+1)*(r-c):Ja(e,t,o),l=a===`ema`?l+2/(s+1)*(r-l):Ja(e,t,s),this.writePoint(n,e,t,Nc(c,l))}return n}};function Nc(e,t){return e===void 0&&t===void 0?null:{...e===void 0?{}:{fast:e},...t===void 0?{}:{slow:t}}}var Pc=class extends B{descriptor={id:`fractals`,name:`Williams Fractals`,placement:`overlay`,defaultConfig:{period:2},shortName:`Fractals`,inputs:{period:{kind:`int`,min:1,max:10}},plots:[{key:`up`,title:`Up`,color:0,kind:`dots`},{key:`down`,title:`Down`,color:1,kind:`dots`}]};read(e){return H(e,`period`,2,1)}lookback(e){return e}pointAt(e,t,n){if(t<n||t>e.length-n-1)return null;let r=!0,i=!0;for(let a=t-n;a<=t+n&&(r||i);a++)a!==t&&(e[a].high>=e[t].high&&(r=!1),e[a].low<=e[t].low&&(i=!1));return!r&&!i?null:{...r?{up:e[t].high}:{},...i?{down:e[t].low}:{}}}},Fc=class extends I{descriptor={id:`cks`,name:`Chande Kroll Stop`,placement:`overlay`,defaultConfig:{p:10,x:1,q:9},shortName:`CKS`,inputs:{p:{kind:`int`,label:`ATR length`,min:1},x:{kind:`number`,label:`ATR multiplier`,min:0,step:.1},q:{kind:`int`,label:`Stop length`,min:1}},plots:[{key:`long`,title:`Stop Long`,color:0},{key:`short`,title:`Stop Short`,color:1}]};states=new WeakMap;workerState(e){return this.states.get(e)}adoptWorkerState(e,t){t&&this.states.set(e,t)}calculate(e,t){let n=H(t,`p`,10,1),r=V(t,`x`,1),i=H(t,`q`,9,1),a={atr:za(Va(e),n),firstHigh:[],firstLow:[]};for(let t=0;t<e.length;t++)Ic(e,a,t,n,r);let o=R(e,e.map((e,t)=>Lc(a,t,i)));return this.states.set(o,a),o}update(e,t,n,r){let i=this.states.get(n);if(!i||!this.canResume(e,n,r))return null;let a=i.atr[r-1];if(a===void 0)return null;let o=H(t,`p`,10,1),s=V(t,`x`,1),c=H(t,`q`,9,1);for(let t=r;t<e.length;t++){let r=e[t-1].close,l=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-r),Math.abs(e[t].low-r));a+=(l-a)/o,i.atr[t]=a,Ic(e,i,t,o,s),this.writePoint(n,e,t,Lc(i,t,c))}return n}};function Ic(e,t,n,r,i){let a=t.atr[n],o=Ka(e,n,r),s=qa(e,n,r);t.firstHigh[n]=o!==void 0&&a!==void 0?o-i*a:void 0,t.firstLow[n]=s!==void 0&&a!==void 0?s+i*a:void 0}function Lc(e,t,n){let r=Ha(e.firstHigh,t,n),i=Ua(e.firstLow,t,n);return r!==void 0&&i!==void 0?{long:i,short:r}:null}var Rc=class extends B{descriptor={id:`bbpb`,name:`Bollinger Bands %B`,placement:`panel`,defaultConfig:{period:20,stdDev:2,source:`close`},shortName:`%B`,inputs:{period:{kind:`int`,min:2},stdDev:{kind:`number`,min:.1,step:.1},source:{source:!0}},plots:[{key:`value`,title:`%B`,color:0}],levels:[0,.5,1]};read(e){return{period:H(e,`period`,20,2),k:V(e,`stdDev`,2)}}pointAt(e,t,{period:n,k:r}){let i=Ga(e,t,n);return!i||i.sd===0?null:{value:(e[t].close-(i.mean-r*i.sd))/(2*r*i.sd)}}},zc=class extends B{descriptor={id:`bbw`,name:`Bollinger BandWidth`,placement:`panel`,defaultConfig:{period:20,stdDev:2,source:`close`},shortName:`BBW`,inputs:{period:{kind:`int`,min:2},stdDev:{kind:`number`,min:.1,step:.1},source:{source:!0}},plots:[{key:`value`,title:`BBW`,color:0}]};read(e){return{period:H(e,`period`,20,2),k:V(e,`stdDev`,2)}}pointAt(e,t,{period:n,k:r}){let i=Ga(e,t,n);return!i||i.mean===0?null:{value:2*r*i.sd/i.mean}}},Bc=class extends B{descriptor={id:`mom`,name:`Momentum`,placement:`panel`,defaultConfig:{period:10,source:`close`},shortName:`MOM`,inputs:{period:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`value`,title:`MOM`,color:0}],levels:[0]};read(e){return H(e,`period`,10,1)}pointAt(e,t,n){return t>=n?{value:e[t].close-e[t-n].close}:null}},Vc=class extends B{descriptor={id:`hv`,name:`Historical Volatility`,placement:`panel`,defaultConfig:{period:10,annual:365,source:`close`},shortName:`HV`,inputs:{period:{kind:`int`,min:2},annual:{kind:`number`,label:`Bars per year`,min:1},source:{source:!0}},plots:[{key:`value`,title:`HV`,color:0}],scale:{min:0}};read(e){return{period:H(e,`period`,10,2),annual:Math.max(1,V(e,`annual`,365))}}pointAt(e,t,{period:n,annual:r}){if(t<n)return null;let i=0,a=0;for(let r=t-n+1;r<=t;r++){let t=e[r-1].close,n=e[r].close;if(!(t>0&&n>0))return null;let o=Math.log(n/t);i+=o,a+=o*o}let o=i/n;return{value:100*Math.sqrt(Math.max(0,a/n-o*o))*Math.sqrt(r)}}},Hc=class extends I{descriptor={id:`vo`,name:`Volume Oscillator`,placement:`panel`,defaultConfig:{short:5,long:10},shortName:`Vol Osc`,inputs:{short:{kind:`int`,min:1},long:{kind:`int`,min:1}},plots:[{key:`value`,title:`Vol Osc`,color:0}],levels:[0]};emas=new WeakMap;workerState(e){return this.emas.get(e)}adoptWorkerState(e,t){t&&this.emas.set(e,t)}calculate(e,t){let n=e.map(e=>e.volume),r=z(n,H(t,`short`,5,1)),i=z(n,H(t,`long`,10,1)),a=R(e,Wa(r.map((e,t)=>Uc(e,i[t]))));return this.emas.set(a,{fast:r,slow:i}),a}update(e,t,n,r){let i=this.emas.get(n);if(!i||!this.canResume(e,n,r))return null;let a=i.fast[r-1],o=i.slow[r-1];if(a===void 0||o===void 0)return null;let s=2/(H(t,`short`,5,1)+1),c=2/(H(t,`long`,10,1)+1);for(let t=r;t<e.length;t++){a+=s*(e[t].volume-a),o+=c*(e[t].volume-o),i.fast[t]=a,i.slow[t]=o;let r=Uc(a,o);this.writePoint(n,e,t,r===void 0?null:{value:r})}return n}};function Uc(e,t){return e===void 0||t===void 0||t===0?void 0:100*(e-t)/t}var Wc=class extends I{descriptor={id:`ulcer`,name:`Ulcer Index`,placement:`panel`,defaultConfig:{period:14,source:`close`},shortName:`Ulcer`,inputs:{period:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`value`,title:`Ulcer`,color:0}],scale:{min:0}};drawdowns=new WeakMap;workerState(e){return this.drawdowns.get(e)}adoptWorkerState(e,t){t&&this.drawdowns.set(e,t)}calculate(e,t){let n=H(t,`period`,14,1),r=e.map((t,r)=>Gc(e,r,n)),i=R(e,e.map((e,t)=>Kc(r,t,n)));return this.drawdowns.set(i,r),i}update(e,t,n,r){let i=this.drawdowns.get(n);if(!i||!this.canResume(e,n,r))return null;let a=H(t,`period`,14,1);for(let t=r;t<e.length;t++)i[t]=Gc(e,t,a);i.length=e.length;for(let t=r;t<e.length;t++)this.writePoint(n,e,t,Kc(i,t,a));return n}};function Gc(e,t,n){if(t<n-1)return;let r=-1/0;for(let i=t-n+1;i<=t;i++)e[i].close>r&&(r=e[i].close);return r===0?void 0:100*(e[t].close-r)/r}function Kc(e,t,n){if(t<n-1)return null;let r=0;for(let i=t-n+1;i<=t;i++){let t=e[i];if(t===void 0)return null;r+=t*t}return{value:Math.sqrt(r/n)}}var qc=class extends I{descriptor={id:`smi`,name:`Stochastic Momentum Index`,placement:`panel`,defaultConfig:{period:10,smooth:3,signal:3},shortName:`SMI`,inputs:{period:{kind:`int`,min:1},smooth:{kind:`int`,min:1},signal:{kind:`int`,min:1}},plots:[{key:`smi`,title:`SMI`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[40,-40]};calculate(e,t){let n=H(t,`period`,10,1),r=H(t,`smooth`,3,1),i=H(t,`signal`,3,1),a=Array(e.length).fill(void 0),o=Array(e.length).fill(void 0);for(let t=n-1;t<e.length;t++){let r=Ka(e,t,n),i=qa(e,t,n);r===void 0||i===void 0||(a[t]=e[t].close-(r+i)/2,o[t]=r-i)}let s=z(z(a,r),r),c=z(z(o,r),r),l=s.map((e,t)=>{let n=c[t]===void 0?void 0:c[t]/2;if(!(e===void 0||n===void 0))return n===0?0:Math.max(-100,Math.min(100,100*e/n))}),u=z(l,i);return R(e,l.map((e,t)=>{if(e===void 0)return null;let n={smi:e};return u[t]!==void 0&&(n.signal=u[t]),n}))}},Jc=class extends I{descriptor={id:`rvix`,name:`Relative Volatility Index`,placement:`panel`,defaultConfig:{period:10,smooth:14},shortName:`RVI (vol)`,inputs:{period:{kind:`int`,min:2},smooth:{kind:`int`,min:1}},plots:[{key:`value`,title:`RVI`,color:0}],levels:[80,50,20],scale:{min:0,max:100}};calculate(e,t){let n=H(t,`period`,10,2),r=H(t,`smooth`,14,1),i=Ba(Fa(e),n),a=i.map((t,n)=>t===void 0||n===0?void 0:e[n].close>e[n-1].close?t:0),o=i.map((t,n)=>t===void 0||n===0?void 0:e[n].close<e[n-1].close?t:0),s=z(a,r),c=z(o,r);return R(e,Wa(s.map((e,t)=>{let n=c[t];if(!(e===void 0||n===void 0))return e+n===0?50:100*e/(e+n)})))}},Yc=class extends B{descriptor={id:`trendstrength`,name:`Trend Strength Index`,placement:`panel`,defaultConfig:{period:14},shortName:`TSI (trend)`,inputs:{period:{kind:`int`,min:2}},plots:[{key:`value`,title:`Trend`,color:0}],levels:[0],scale:{min:-1,max:1}};read(e){return H(e,`period`,14,2)}pointAt(e,t,n){let r=Ya(e,t,n);return r?{value:r.r}:null}},Xc=class extends B{descriptor={id:`lrslope`,name:`Linear Regression Slope`,placement:`panel`,defaultConfig:{period:14},shortName:`LR Slope`,inputs:{period:{kind:`int`,min:2}},plots:[{key:`value`,title:`Slope`,color:0}],levels:[0]};read(e){return H(e,`period`,14,2)}pointAt(e,t,n){let r=Ya(e,t,n);return r?{value:r.slope}:null}},Zc=class extends B{descriptor={id:`stderror`,name:`Standard Error`,placement:`panel`,defaultConfig:{period:14},shortName:`StdErr`,inputs:{period:{kind:`int`,min:3}},plots:[{key:`value`,title:`StdErr`,color:0}],scale:{min:0}};read(e){return H(e,`period`,14,3)}pointAt(e,t,n){let r=Ya(e,t,n);return r?{value:r.stdErr}:null}},Qc=class extends B{descriptor={id:`adr`,name:`Average Day Range`,placement:`panel`,defaultConfig:{period:14},shortName:`ADR`,inputs:{period:{kind:`int`,min:1}},plots:[{key:`value`,title:`ADR`,color:0}],scale:{min:0}};read(e){return H(e,`period`,14,1)}pointAt(e,t,n){if(t<n-1)return null;let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i].high-e[i].low;return{value:r/n}}},$c=class extends B{descriptor={id:`netvolume`,name:`Net Volume`,placement:`panel`,defaultConfig:{},shortName:`Net Vol`,plots:[{key:`value`,title:`Net`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}],levels:[0]};read(e){return null}pointAt(e,t){if(t===0)return null;let n=e[t].close-e[t-1].close,r=e[t].volume??0;return{value:n>0?r:n<0?-r:0,up:+(n>=0)}}lookback(){return 1}},el=class extends I{descriptor={id:`seb`,name:`Standard Error Bands`,placement:`overlay`,defaultConfig:{period:21,mult:2,smooth:3},shortName:`SEB`,inputs:{period:{kind:`int`,min:3},mult:{kind:`number`,min:0,step:.1},smooth:{kind:`int`,min:1}},plots:[{key:`upper`,title:`Upper`,color:1},{key:`middle`,title:`Middle`,color:0},{key:`lower`,title:`Lower`,color:1}]};calculate(e,t){let n=H(t,`period`,21,3),r=V(t,`mult`,2),i=H(t,`smooth`,3,1),a=Array(e.length).fill(void 0),o=Array(e.length).fill(void 0),s=Array(e.length).fill(void 0);for(let t=0;t<e.length;t++){let i=Ya(e,t,n);i&&(a[t]=i.end,o[t]=i.end+r*i.stdErr,s[t]=i.end-r*i.stdErr)}let c=Ia(a,i),l=Ia(o,i),u=Ia(s,i);return R(e,c.map((e,t)=>e===void 0||l[t]===void 0||u[t]===void 0?null:{middle:e,upper:l[t],lower:u[t]}))}},tl=[3,5,8,10,12,15],nl=[30,35,40,45,50,60],rl=class extends I{descriptor={id:`gmma`,name:`Guppy Multiple Moving Average`,placement:`overlay`,defaultConfig:{},shortName:`GMMA`,plots:[...tl.map(e=>({key:`s${e}`,title:`EMA ${e}`,color:0})),...nl.map(e=>({key:`l${e}`,title:`EMA ${e}`,color:1}))]};calculate(e,t){let n=Fa(e),r=[...tl.map(e=>[`s${e}`,z(n,e)]),...nl.map(e=>[`l${e}`,z(n,e)])];return R(e,e.map((e,t)=>{let n={},i=!1;for(let[e,a]of r)a[t]!==void 0&&(n[e]=a[t],i=!0);return i?n:null}))}},il=class extends I{descriptor={id:`maribbon`,name:`Moving Average Ribbon`,placement:`overlay`,defaultConfig:{ma1:20,ma2:50,ma3:100,ma4:200,exponential:0},shortName:`MA Ribbon`,inputs:{ma1:{kind:`int`,min:1},ma2:{kind:`int`,min:1},ma3:{kind:`int`,min:1},ma4:{kind:`int`,min:1},exponential:{kind:`int`,min:0,max:1}},plots:[{key:`ma1`,title:`MA 1`,color:0},{key:`ma2`,title:`MA 2`,color:1},{key:`ma3`,title:`MA 3`,color:2},{key:`ma4`,title:`MA 4`,color:3}]};calculate(e,t){let n=V(t,`exponential`,0)>=1?z:Ia,r=Fa(e),i=[`ma1`,`ma2`,`ma3`,`ma4`],a=[20,50,100,200],o=i.map((e,i)=>[e,n(r,H(t,e,a[i],1))]);return R(e,e.map((e,t)=>{let n={},r=!1;for(let[e,i]of o)i[t]!==void 0&&(n[e]=i[t],r=!0);return r?n:null}))}},al=class extends B{read(e){return null}pointAt(e,t){return{value:this.price(e[t])}}},ol=class extends al{descriptor={id:`avgprice`,name:`Average Price`,placement:`overlay`,defaultConfig:{},shortName:`OHLC4`,plots:[{key:`value`,title:`Average`,color:0}]};price(e){return(e.open+e.high+e.low+e.close)/4}},sl=class extends al{descriptor={id:`medprice`,name:`Median Price`,placement:`overlay`,defaultConfig:{},shortName:`HL2`,plots:[{key:`value`,title:`Median`,color:0}]};price(e){return(e.high+e.low)/2}},cl=class extends al{descriptor={id:`typprice`,name:`Typical Price`,placement:`overlay`,defaultConfig:{},shortName:`HLC3`,plots:[{key:`value`,title:`Typical`,color:0}]};price(e){return(e.high+e.low+e.close)/3}},ll=class extends al{descriptor={id:`wclose`,name:`Weighted Close`,placement:`overlay`,defaultConfig:{},shortName:`HLCC4`,plots:[{key:`value`,title:`Weighted`,color:0}]};price(e){return(e.high+e.low+2*e.close)/4}},ul=class extends B{descriptor={id:`psy`,name:`Psychological Line`,placement:`panel`,defaultConfig:{period:10},inputs:{period:{kind:`int`,min:1}},shortName:`PSY`,plots:[{key:`value`,title:`PSY`,color:0}],scale:{min:0,max:100},levels:[25,75]};read(e){return H(e,`period`,10,1)}pointAt(e,t,n){if(t<n)return null;let r=0;for(let i=t-n+1;i<=t;i++)e[i].close>e[i-1].close&&r++;return{value:r/n*100}}},dl=class extends B{descriptor={id:`newpsy`,name:`New Psychological Line`,placement:`panel`,defaultConfig:{period:10},inputs:{period:{kind:`int`,min:1}},shortName:`New PSY`,plots:[{key:`value`,title:`New PSY`,color:0}],scale:{min:-100,max:100},levels:[-50,0,50]};read(e){return H(e,`period`,10,1)}pointAt(e,t,n){if(t<n)return null;let r=0,i=0,a=0,o=0;for(let s=t-n+1;s<=t;s++){let t=e[s].close-e[s-1].close;t>0?(r++,a+=t):t<0&&(i++,o-=t)}let s=a+o;return{value:s===0?0:(r*a-i*o)/(s*n)*100}}},fl=class extends B{descriptor={id:`vr`,name:`Volume Ratio`,placement:`panel`,defaultConfig:{period:20},inputs:{period:{kind:`int`,min:1}},shortName:`VR`,plots:[{key:`value`,title:`VR`,color:0}],levels:[70,150,450]};read(e){return H(e,`period`,20,1)}pointAt(e,t,n){if(t<n)return null;let r=0,i=0,a=0;for(let o=t-n+1;o<=t;o++){let t=e[o].close-e[o-1].close;t>0?r+=e[o].volume:t<0?i+=e[o].volume:a+=e[o].volume}let o=i+a/2;return o>0?{value:(r+a/2)/o*100}:null}},pl=class extends B{descriptor={id:`abratio`,name:`AB Ratio`,placement:`panel`,defaultConfig:{period:26},inputs:{period:{kind:`int`,min:1}},shortName:`AB Ratio`,plots:[{key:`a`,title:`A`,color:0},{key:`b`,title:`B`,color:1}],levels:[100]};read(e){return H(e,`period`,26,1)}pointAt(e,t,n){if(t<n)return null;let r=0,i=0,a=0,o=0;for(let s=t-n+1;s<=t;s++){let{open:t,high:n,low:c}=e[s],l=e[s-1].close;r+=n-t,i+=t-c,a+=Math.max(0,n-l),o+=Math.max(0,l-c)}let s={};return i>0&&(s.a=r/i*100),o>0&&(s.b=a/o*100),s.a!==void 0||s.b!==void 0?s:null}},ml=class extends I{descriptor={id:`sonar`,name:`Sonar`,placement:`panel`,defaultConfig:{period:20,lookback:9,signal:9},inputs:{period:{kind:`int`,min:1},lookback:{kind:`int`,min:1},signal:{kind:`int`,min:1}},shortName:`Sonar`,plots:[{key:`sonar`,title:`Sonar`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=H(t,`period`,20,1),r=H(t,`lookback`,9,1),i=H(t,`signal`,9,1),a=z(Fa(e),n),o=a.map((e,t)=>e!==void 0&&t>=r&&a[t-r]!==void 0?e-a[t-r]:void 0),s=z(o,i);return R(e,o.map((e,t)=>e===void 0?null:s[t]===void 0?{sonar:e}:{sonar:e,signal:s[t]}))}},hl=class extends B{descriptor={id:`sigma`,name:`Sigma`,placement:`panel`,defaultConfig:{period:20},inputs:{period:{kind:`int`,min:2}},shortName:`Sigma`,plots:[{key:`value`,title:`Sigma`,color:0}],levels:[-2,0,2]};read(e){return H(e,`period`,20,2)}pointAt(e,t,n){let r=Ga(e,t,n);return r?{value:r.sd<=Math.abs(r.mean)*1e-9?0:(e[t].close-r.mean)/r.sd}:null}},gl=class extends B{descriptor={id:`vhf`,name:`Vertical Horizontal Filter`,placement:`panel`,defaultConfig:{period:28},inputs:{period:{kind:`int`,min:1}},shortName:`VHF`,plots:[{key:`value`,title:`VHF`,color:0}]};read(e){return H(e,`period`,28,1)}pointAt(e,t,n){if(t<n)return null;let r=e[t-n].close,i=r,a=0;for(let o=t-n+1;o<=t;o++){let t=e[o].close;t>r&&(r=t),t<i&&(i=t),a+=Math.abs(t-e[o-1].close)}return a>0?{value:(r-i)/a}:null}},_l=class extends B{descriptor={id:`rsquared`,name:`R-Squared`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:2}},shortName:`R²`,plots:[{key:`value`,title:`R²`,color:0}],scale:{min:0,max:1}};read(e){return H(e,`period`,14,2)}pointAt(e,t,n){let r=Ya(e,t,n);return r?{value:r.r*r.r}:null}};function vl(e,t){let n=e[t];if(t===0)return n.high-n.low;let r=e[t-1].close;return Math.max(n.high-n.low,Math.abs(n.high-r),Math.abs(n.low-r))}var yl=class extends B{descriptor={id:`rwi`,name:`Random Walk Index`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:2}},shortName:`RWI`,plots:[{key:`high`,title:`RWI High`,color:0},{key:`low`,title:`RWI Low`,color:1}],levels:[1]};read(e){return H(e,`period`,14,2)}pointAt(e,t,n){if(t<n)return null;let r=0,i=0,a=vl(e,t);for(let o=1;o<=n;o++){if(o>1){let n=a/o*Math.sqrt(o);n>0&&(r=Math.max(r,(e[t].high-e[t-o].low)/n),i=Math.max(i,(e[t-o].high-e[t].low)/n))}a+=vl(e,t-o)}return{high:r,low:i}}},bl=1e3,xl=class extends I{calculate(e,t){let n=Array(e.length).fill(void 0),r=bl;for(let t=0;t<e.length;t++){if(t>0){let n=e[t-1].close;n!==0&&this.counts(e[t].volume,e[t-1].volume)&&(r*=e[t].close/n)}n[t]=r}let i=z(n,H(t,`signal`,255,1));return R(e,n.map((e,t)=>i[t]===void 0?{value:e}:{value:e,signal:i[t]}))}},Sl=class extends xl{descriptor={id:`nvi`,name:`Negative Volume Index`,placement:`panel`,defaultConfig:{signal:255},inputs:{signal:{kind:`int`,min:1}},shortName:`NVI`,plots:[{key:`value`,title:`NVI`,color:0},{key:`signal`,title:`Signal`,color:1}]};counts(e,t){return e<t}},Cl=class extends xl{descriptor={id:`pvi`,name:`Positive Volume Index`,placement:`panel`,defaultConfig:{signal:255},inputs:{signal:{kind:`int`,min:1}},shortName:`PVI`,plots:[{key:`value`,title:`PVI`,color:0},{key:`signal`,title:`Signal`,color:1}]};counts(e,t){return e>t}},wl=class extends B{descriptor={id:`tr`,name:`True Range`,placement:`panel`,defaultConfig:{},shortName:`TR`,plots:[{key:`value`,title:`TR`,color:0}]};read(e){return null}pointAt(e,t){let n=e[t];if(t===0)return{value:n.high-n.low};let r=e[t-1].close;return{value:Math.max(n.high-n.low,Math.abs(n.high-r),Math.abs(n.low-r))}}},Tl=class extends B{descriptor={id:`iii`,name:`Intraday Intensity`,placement:`panel`,defaultConfig:{period:21},inputs:{period:{kind:`int`,min:1}},shortName:`III`,plots:[{key:`value`,title:`III %`,color:0,kind:`histogram`,tone:`sign`,downColor:1}],scale:{zero:!0},levels:[0]};read(e){return H(e,`period`,21,1)}pointAt(e,t,n){if(t<n-1)return null;let r=0,i=0;for(let a=t-n+1;a<=t;a++){let t=e[a];i+=t.volume,t.high>t.low&&(r+=t.volume*(2*t.close-t.high-t.low)/(t.high-t.low))}return i>0?{value:Math.max(-100,Math.min(100,r/i*100))}:{value:0}}},El=class extends B{descriptor={id:`volpct`,name:`Volume vs Average`,placement:`panel`,defaultConfig:{period:20},inputs:{period:{kind:`int`,min:1}},shortName:`Vol %`,plots:[{key:`value`,title:`Vol %`,color:0,kind:`histogram`,tone:`sign`,downColor:1}],scale:{zero:!0},levels:[0]};read(e){return H(e,`period`,20,1)}pointAt(e,t,n){if(t<n-1)return null;let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i].volume;let i=r/n,a=(e[t].volume-i)/i*100;return i>0&&Number.isFinite(a)?{value:a}:null}},Dl=class extends B{descriptor={id:`volchange`,name:`Volume Change`,placement:`panel`,defaultConfig:{},shortName:`Vol Δ`,plots:[{key:`value`,title:`Volume`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}],scale:{zero:!0}};read(e){return null}pointAt(e,t){let{volume:n}=e[t];return Number.isFinite(n)?{value:n,up:+(t===0||n>=e[t-1].volume)}:null}},Ol=class extends B{descriptor={id:`tradevalue`,name:`Trade Value`,placement:`panel`,defaultConfig:{},shortName:`Value`,plots:[{key:`value`,title:`Value`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}],scale:{zero:!0}};read(e){return null}pointAt(e,t){let n=e[t],r=n.close*n.volume;return Number.isFinite(r)?{value:r,up:+(n.close>=n.open)}:null}},kl=class extends I{descriptor={id:`binarywave`,name:`Binary Wave`,placement:`panel`,defaultConfig:{ma:20,fast:12,slow:26,signal:9,roc:12,stoch:14},inputs:{ma:{kind:`int`,min:1},fast:{kind:`int`,min:1},slow:{kind:`int`,min:1},signal:{kind:`int`,min:1},roc:{kind:`int`,min:1},stoch:{kind:`int`,min:1}},shortName:`Binary Wave`,plots:[{key:`value`,title:`Wave`,color:0,kind:`step`}],scale:{min:-4,max:4},levels:[0]};calculate(e,t){let n=Fa(e),r=Ia(n,H(t,`ma`,20,1)),i=z(n,H(t,`fast`,12,1)),a=z(n,H(t,`slow`,26,1)),o=i.map((e,t)=>e!==void 0&&a[t]!==void 0?e-a[t]:void 0),s=z(o,H(t,`signal`,9,1)),c=H(t,`roc`,12,1),l=H(t,`stoch`,14,1),u=e=>e?1:-1;return R(e,Wa(e.map((t,i)=>{let a=Ka(e,i,l),d=qa(e,i,l);if(r[i]===void 0||o[i]===void 0||s[i]===void 0||i<c||a===void 0||d===void 0)return;let f=a>d?(t.close-d)/(a-d)*100:50;return u(t.close>r[i])+u(o[i]>s[i])+u(t.close>n[i-c])+u(f>50)})))}},Al=class extends I{descriptor={id:`sroc`,name:`Smoothed Rate of Change`,placement:`panel`,defaultConfig:{ema:13,roc:21},inputs:{ema:{kind:`int`,min:1},roc:{kind:`int`,min:1}},shortName:`S-ROC`,plots:[{key:`value`,title:`S-ROC`,color:0}],levels:[0]};calculate(e,t){let n=z(Fa(e),H(t,`ema`,13,1)),r=H(t,`roc`,21,1);return R(e,Wa(n.map((e,t)=>{let i=t>=r?n[t-r]:void 0;return e!==void 0&&i!==void 0&&i!==0?(e-i)/Math.abs(i)*100:void 0})))}},jl=class extends B{descriptor={id:`tsf`,name:`Time Series Forecast`,placement:`overlay`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:2}},shortName:`TSF`,plots:[{key:`value`,title:`TSF`,color:0}]};read(e){return H(e,`period`,14,2)}pointAt(e,t,n){let r=Ya(e,t,n);return r?{value:r.end+r.slope}:null}},Ml=class extends B{descriptor={id:`demark`,name:`DeMark Projected Range`,placement:`overlay`,defaultConfig:{},shortName:`DeMark`,plots:[{key:`high`,title:`Projected high`,color:0,kind:`step`},{key:`low`,title:`Projected low`,color:1,kind:`step`}]};read(e){return null}pointAt(e,t){if(t===0)return null;let{open:n,high:r,low:i,close:a}=e[t-1],o=a>n?2*r+i+a:a<n?r+2*i+a:r+i+2*a;return{high:o/2-i,low:o/2-r}}},Nl=class extends I{descriptor={id:`rainbow`,name:`Moving Average Rainbow`,placement:`overlay`,defaultConfig:{first:10,step:10,count:10,exponential:0},shortName:`Rainbow`,inputs:{first:{kind:`int`,min:1},step:{kind:`int`,min:1},count:{kind:`int`,min:1,max:20},exponential:{kind:`int`,min:0,max:1}},plots:Array.from({length:20},(e,n)=>({key:`ma${n+1}`,title:`MA ${n+1}`,color:n%t.TC_SERIES_COLORS.length}))};calculate(e,t){let n=H(t,`first`,10,1),r=H(t,`step`,10,1),i=Math.min(20,H(t,`count`,10,1)),a=H(t,`exponential`,0,0)>=1?z:Ia,o=Fa(e),s=Array.from({length:i},(e,t)=>[`ma${t+1}`,a(o,n+t*r)]);return R(e,e.map((e,t)=>{let n={},r=!1;for(let[e,i]of s)i[t]!==void 0&&(n[e]=i[t],r=!0);return r?n:null}))}},Pl=.05,Fl=class{bodies=new Map;ranges=new Map;trends=new Map;constructor(e,t){this.data=e,this.period=t}open(e){return this.data[e].open}high(e){return this.data[e].high}low(e){return this.data[e].low}close(e){return this.data[e].close}body(e){return Math.abs(this.data[e].close-this.data[e].open)}range(e){return this.data[e].high-this.data[e].low}bodyTop(e){return Math.max(this.data[e].open,this.data[e].close)}bodyBottom(e){return Math.min(this.data[e].open,this.data[e].close)}mid(e){return(this.data[e].open+this.data[e].close)/2}upper(e){return this.data[e].high-this.bodyTop(e)}lower(e){return this.bodyBottom(e)-this.data[e].low}white(e){return this.data[e].close>this.data[e].open}black(e){return this.data[e].close<this.data[e].open}avgBody(e){let t=this.bodies.get(e);return t===void 0&&(t=this.averageBefore(e,e=>this.body(e)),this.bodies.set(e,t)),t}avgRange(e){let t=this.ranges.get(e);return t===void 0&&(t=this.averageBefore(e,e=>this.range(e)),this.ranges.set(e,t)),t}averageBefore(e,t){let n=Math.max(0,e-this.period);if(e<=n)return t(e);let r=0;for(let i=n;i<e;i++)r+=t(i);return r/(e-n)}bodyScale(e){return Math.max(this.avgBody(e),this.avgRange(e)*.25)}long(e,t=e){let n=this.bodyScale(t);return n>0&&this.body(e)>n}short(e,t=e){return this.body(e)<this.bodyScale(t)*.5}doji(e){return this.range(e)>0&&this.body(e)<=this.range(e)*.1}marubozu(e,t=e){return this.long(e,t)&&this.upper(e)<=this.range(e)*.05&&this.lower(e)<=this.range(e)*.05}same(e,t,n){return Math.abs(e-t)<=this.avgRange(n)*Pl}bodyGapUp(e,t){return this.bodyBottom(t)>this.bodyTop(e)}bodyGapDown(e,t){return this.bodyTop(t)<this.bodyBottom(e)}bodyInside(e,t){return this.bodyTop(t)<=this.bodyTop(e)&&this.bodyBottom(t)>=this.bodyBottom(e)&&this.body(t)<this.body(e)}trendBefore(e){let t=this.trends.get(e);return t===void 0&&(t=this.readTrend(e),this.trends.set(e,t)),t}readTrend(e){let t=e-1;if(t<this.period-1)return null;let n=0;for(let e=t-this.period+1;e<=t;e++)n+=this.close(e);let r=n/this.period,i=this.close(t),a=this.close(t-this.period+1);return i>r&&i>a?`up`:i<r&&i<a?`down`:null}};function U(e,t,n,r,i,a,o,s){return{info:Object.freeze({id:e,name:t,short:n,direction:r,kind:i,bars:a}),trend:o,test:s}}function Il(e,t){let n=e.range(t);return n>0&&n>=e.avgRange(t)*.5&&e.body(t)<=n*.35&&e.lower(t)>=2*Math.max(e.body(t),n*.05)&&e.upper(t)<=n*.1}function Ll(e,t){let n=e.range(t);return n>0&&n>=e.avgRange(t)*.5&&e.body(t)<=n*.35&&e.upper(t)>=2*Math.max(e.body(t),n*.05)&&e.lower(t)<=n*.1}var Rl=[U(`doji`,`Doji`,`Doji`,`neutral`,`indecision`,1,null,(e,t)=>e.doji(t)),U(`longLeggedDoji`,`Long-Legged Doji`,`LL Doji`,`neutral`,`indecision`,1,null,(e,t)=>e.doji(t)&&e.upper(t)>=e.range(t)*.3&&e.lower(t)>=e.range(t)*.3&&e.range(t)>e.avgRange(t)),U(`dragonflyDoji`,`Dragonfly Doji`,`Dragonfly`,`bullish`,`reversal`,1,`down`,(e,t)=>e.doji(t)&&e.upper(t)<=e.range(t)*.1&&e.lower(t)>=e.range(t)*.6),U(`gravestoneDoji`,`Gravestone Doji`,`Gravestone`,`bearish`,`reversal`,1,`up`,(e,t)=>e.doji(t)&&e.lower(t)<=e.range(t)*.1&&e.upper(t)>=e.range(t)*.6),U(`hammer`,`Hammer`,`Hammer`,`bullish`,`reversal`,1,`down`,Il),U(`hangingMan`,`Hanging Man`,`Hanging`,`bearish`,`reversal`,1,`up`,Il),U(`invertedHammer`,`Inverted Hammer`,`Inv Hammer`,`bullish`,`reversal`,1,`down`,Ll),U(`shootingStar`,`Shooting Star`,`Shooting`,`bearish`,`reversal`,1,`up`,Ll),U(`spinningTop`,`Spinning Top`,`Spinning`,`neutral`,`indecision`,1,null,(e,t)=>!e.doji(t)&&e.body(t)<=e.range(t)*.3&&e.upper(t)>e.body(t)&&e.lower(t)>e.body(t)),U(`bullishMarubozu`,`Bullish Marubozu`,`Marubozu`,`bullish`,`continuation`,1,null,(e,t)=>e.white(t)&&e.marubozu(t)),U(`bearishMarubozu`,`Bearish Marubozu`,`Marubozu`,`bearish`,`continuation`,1,null,(e,t)=>e.black(t)&&e.marubozu(t)),U(`bullishBeltHold`,`Bullish Belt Hold`,`Belt Hold`,`bullish`,`reversal`,1,`down`,(e,t)=>e.white(t)&&e.long(t)&&e.lower(t)<=e.range(t)*.05&&e.upper(t)>e.range(t)*.05),U(`bearishBeltHold`,`Bearish Belt Hold`,`Belt Hold`,`bearish`,`reversal`,1,`up`,(e,t)=>e.black(t)&&e.long(t)&&e.upper(t)<=e.range(t)*.05&&e.lower(t)>e.range(t)*.05)],zl=[U(`bullishEngulfing`,`Bullish Engulfing`,`Engulf`,`bullish`,`reversal`,2,`down`,(e,t)=>{let n=t-1;return e.black(n)&&e.white(t)&&e.open(t)<=e.close(n)&&e.close(t)>=e.open(n)&&e.body(t)>e.body(n)}),U(`bearishEngulfing`,`Bearish Engulfing`,`Engulf`,`bearish`,`reversal`,2,`up`,(e,t)=>{let n=t-1;return e.white(n)&&e.black(t)&&e.open(t)>=e.close(n)&&e.close(t)<=e.open(n)&&e.body(t)>e.body(n)}),U(`bullishHarami`,`Bullish Harami`,`Harami`,`bullish`,`reversal`,2,`down`,(e,t)=>e.black(t-1)&&e.long(t-1,t-1)&&!e.doji(t)&&e.bodyInside(t-1,t)&&e.body(t)<e.body(t-1)*.6),U(`bearishHarami`,`Bearish Harami`,`Harami`,`bearish`,`reversal`,2,`up`,(e,t)=>e.white(t-1)&&e.long(t-1,t-1)&&!e.doji(t)&&e.bodyInside(t-1,t)&&e.body(t)<e.body(t-1)*.6),U(`bullishHaramiCross`,`Bullish Harami Cross`,`Harami +`,`bullish`,`reversal`,2,`down`,(e,t)=>e.black(t-1)&&e.long(t-1,t-1)&&e.doji(t)&&e.bodyInside(t-1,t)),U(`bearishHaramiCross`,`Bearish Harami Cross`,`Harami +`,`bearish`,`reversal`,2,`up`,(e,t)=>e.white(t-1)&&e.long(t-1,t-1)&&e.doji(t)&&e.bodyInside(t-1,t)),U(`piercingLine`,`Piercing Line`,`Piercing`,`bullish`,`reversal`,2,`down`,(e,t)=>{let n=t-1;return e.black(n)&&e.long(n,n)&&e.white(t)&&e.open(t)<e.low(n)&&e.close(t)>e.mid(n)&&e.close(t)<e.open(n)}),U(`darkCloudCover`,`Dark Cloud Cover`,`Dark Cloud`,`bearish`,`reversal`,2,`up`,(e,t)=>{let n=t-1;return e.white(n)&&e.long(n,n)&&e.black(t)&&e.open(t)>e.high(n)&&e.close(t)<e.mid(n)&&e.close(t)>e.open(n)}),U(`tweezerBottom`,`Tweezer Bottom`,`Tweezer`,`bullish`,`reversal`,2,`down`,(e,t)=>e.black(t-1)&&e.white(t)&&e.same(e.low(t-1),e.low(t),t-1)),U(`tweezerTop`,`Tweezer Top`,`Tweezer`,`bearish`,`reversal`,2,`up`,(e,t)=>e.white(t-1)&&e.black(t)&&e.same(e.high(t-1),e.high(t),t-1)),U(`bullishKicking`,`Bullish Kicking`,`Kicking`,`bullish`,`reversal`,2,null,(e,t)=>e.black(t-1)&&e.marubozu(t-1,t-1)&&e.white(t)&&e.marubozu(t,t-1)&&e.low(t)>e.high(t-1)),U(`bearishKicking`,`Bearish Kicking`,`Kicking`,`bearish`,`reversal`,2,null,(e,t)=>e.white(t-1)&&e.marubozu(t-1,t-1)&&e.black(t)&&e.marubozu(t,t-1)&&e.high(t)<e.low(t-1)),U(`bullishCounterattack`,`Bullish Counterattack`,`Counter`,`bullish`,`reversal`,2,`down`,(e,t)=>e.black(t-1)&&e.long(t-1,t-1)&&e.white(t)&&e.long(t,t-1)&&e.same(e.close(t),e.close(t-1),t-1)),U(`bearishCounterattack`,`Bearish Counterattack`,`Counter`,`bearish`,`reversal`,2,`up`,(e,t)=>e.white(t-1)&&e.long(t-1,t-1)&&e.black(t)&&e.long(t,t-1)&&e.same(e.close(t),e.close(t-1),t-1)),U(`matchingLow`,`Matching Low`,`Match Low`,`bullish`,`reversal`,2,`down`,(e,t)=>e.black(t-1)&&e.long(t-1,t-1)&&e.black(t)&&e.same(e.close(t),e.close(t-1),t-1)),U(`homingPigeon`,`Homing Pigeon`,`Pigeon`,`bullish`,`reversal`,2,`down`,(e,t)=>e.black(t-1)&&e.long(t-1,t-1)&&e.black(t)&&e.short(t,t-1)&&e.bodyInside(t-1,t)),U(`onNeck`,`On Neck`,`On Neck`,`bearish`,`continuation`,2,`down`,(e,t)=>{let n=t-1;return e.black(n)&&e.long(n,n)&&e.white(t)&&e.open(t)<e.low(n)&&e.same(e.close(t),e.low(n),n)&&e.close(t)<e.close(n)}),U(`inNeck`,`In Neck`,`In Neck`,`bearish`,`continuation`,2,`down`,(e,t)=>{let n=t-1;return e.black(n)&&e.long(n,n)&&e.white(t)&&e.open(t)<e.low(n)&&e.close(t)>e.close(n)&&e.close(t)<=e.close(n)+e.body(n)*.1}),U(`thrusting`,`Thrusting`,`Thrusting`,`bearish`,`continuation`,2,`down`,(e,t)=>{let n=t-1;return e.black(n)&&e.long(n,n)&&e.white(t)&&e.open(t)<e.low(n)&&e.close(t)>e.close(n)+e.body(n)*.1&&e.close(t)<e.mid(n)}),U(`bullishSeparatingLines`,`Bullish Separating Lines`,`Separating`,`bullish`,`continuation`,2,`up`,(e,t)=>e.black(t-1)&&e.white(t)&&e.long(t,t-1)&&e.lower(t)<=e.range(t)*.05&&e.same(e.open(t),e.open(t-1),t-1)),U(`bearishSeparatingLines`,`Bearish Separating Lines`,`Separating`,`bearish`,`continuation`,2,`down`,(e,t)=>e.white(t-1)&&e.black(t)&&e.long(t,t-1)&&e.upper(t)<=e.range(t)*.05&&e.same(e.open(t),e.open(t-1),t-1))];function Bl(e,t){for(let n=t;n<t+3;n++)if(!e.white(n)||e.short(n,t)||e.upper(n)>e.body(n)*.25||n>t&&(e.close(n)<=e.close(n-1)||e.open(n)<e.open(n-1)||e.open(n)>e.close(n-1)))return!1;return!0}function Vl(e,t){for(let n=t;n<t+3;n++)if(!e.black(n)||e.short(n,t)||e.lower(n)>e.body(n)*.25||n>t&&(e.close(n)>=e.close(n-1)||e.open(n)>e.open(n-1)||e.open(n)<e.close(n-1)))return!1;return!0}function Hl(e,t,n,r){for(let i=t+1;i<=n;i++)if(r?e.close(i)>=e.close(i-1):e.close(i)<=e.close(i-1))return!1;return!0}function Ul(e,t,n,r,i){for(let a=n;a<=r;a++)if((i?!e.black(a):!e.white(a))||e.long(a,t)||e.high(a)>e.high(t)||e.low(a)<e.low(t))return!1;return!0}var Wl=[U(`morningStar`,`Morning Star`,`M. Star`,`bullish`,`reversal`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.long(n,n)&&e.short(r,n)&&!e.doji(r)&&e.bodyGapDown(n,r)&&e.white(t)&&e.close(t)>e.mid(n)}),U(`eveningStar`,`Evening Star`,`E. Star`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.long(n,n)&&e.short(r,n)&&!e.doji(r)&&e.bodyGapUp(n,r)&&e.black(t)&&e.close(t)<e.mid(n)}),U(`morningDojiStar`,`Morning Doji Star`,`M. Doji`,`bullish`,`reversal`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.long(n,n)&&e.doji(r)&&e.bodyGapDown(n,r)&&e.white(t)&&e.close(t)>e.mid(n)}),U(`eveningDojiStar`,`Evening Doji Star`,`E. Doji`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.long(n,n)&&e.doji(r)&&e.bodyGapUp(n,r)&&e.black(t)&&e.close(t)<e.mid(n)}),U(`bullishAbandonedBaby`,`Bullish Abandoned Baby`,`Abandoned`,`bullish`,`reversal`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.long(n,n)&&e.doji(r)&&e.high(r)<e.low(n)&&e.white(t)&&!e.short(t,n)&&e.low(t)>e.high(r)}),U(`bearishAbandonedBaby`,`Bearish Abandoned Baby`,`Abandoned`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.long(n,n)&&e.doji(r)&&e.low(r)>e.high(n)&&e.black(t)&&!e.short(t,n)&&e.high(t)<e.low(r)}),U(`threeWhiteSoldiers`,`Three White Soldiers`,`3 Soldiers`,`bullish`,`reversal`,3,null,(e,t)=>Bl(e,t-2)),U(`threeBlackCrows`,`Three Black Crows`,`3 Crows`,`bearish`,`reversal`,3,null,(e,t)=>Vl(e,t-2)),U(`threeInsideUp`,`Three Inside Up`,`3 Inside`,`bullish`,`reversal`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.long(n,n)&&e.white(r)&&e.bodyInside(n,r)&&e.white(t)&&e.close(t)>e.open(n)}),U(`threeInsideDown`,`Three Inside Down`,`3 Inside`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.long(n,n)&&e.black(r)&&e.bodyInside(n,r)&&e.black(t)&&e.close(t)<e.open(n)}),U(`threeOutsideUp`,`Three Outside Up`,`3 Outside`,`bullish`,`reversal`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.white(r)&&e.open(r)<=e.close(n)&&e.close(r)>=e.open(n)&&e.body(r)>e.body(n)&&e.white(t)&&e.close(t)>e.close(r)}),U(`threeOutsideDown`,`Three Outside Down`,`3 Outside`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.black(r)&&e.open(r)>=e.close(n)&&e.close(r)<=e.open(n)&&e.body(r)>e.body(n)&&e.black(t)&&e.close(t)<e.close(r)}),U(`upsideGapTwoCrows`,`Upside Gap Two Crows`,`2 Crows Gap`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.long(n,n)&&e.black(r)&&e.short(r,n)&&e.bodyGapUp(n,r)&&e.black(t)&&e.open(t)>e.open(r)&&e.close(t)<e.close(r)&&e.close(t)>e.close(n)}),U(`twoCrows`,`Two Crows`,`2 Crows`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.long(n,n)&&e.black(r)&&e.bodyGapUp(n,r)&&e.black(t)&&e.open(t)<e.open(r)&&e.open(t)>e.close(r)&&e.close(t)<e.close(n)&&e.close(t)>e.open(n)}),U(`bullishTriStar`,`Bullish Tri-Star`,`Tri-Star`,`bullish`,`reversal`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.doji(n)&&e.doji(r)&&e.doji(t)&&e.bodyGapDown(n,r)&&e.bodyGapUp(r,t)}),U(`bearishTriStar`,`Bearish Tri-Star`,`Tri-Star`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.doji(n)&&e.doji(r)&&e.doji(t)&&e.bodyGapUp(n,r)&&e.bodyGapDown(r,t)}),U(`upsideTasukiGap`,`Upside Tasuki Gap`,`Tasuki`,`bullish`,`continuation`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.white(r)&&e.low(r)>e.high(n)&&e.black(t)&&e.open(t)<e.close(r)&&e.open(t)>e.open(r)&&e.close(t)<e.low(r)&&e.close(t)>e.high(n)}),U(`downsideTasukiGap`,`Downside Tasuki Gap`,`Tasuki`,`bearish`,`continuation`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.black(r)&&e.high(r)<e.low(n)&&e.white(t)&&e.open(t)>e.close(r)&&e.open(t)<e.open(r)&&e.close(t)>e.high(r)&&e.close(t)<e.low(n)}),U(`stickSandwich`,`Stick Sandwich`,`Sandwich`,`bullish`,`reversal`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.white(r)&&e.low(r)>e.close(n)&&e.black(t)&&e.same(e.close(t),e.close(n),n)}),U(`advanceBlock`,`Advance Block`,`Adv Block`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.long(n,n)&&e.white(r)&&e.white(t)&&e.close(r)>e.close(n)&&e.close(t)>e.close(r)&&e.open(r)>e.open(n)&&e.open(r)<=e.close(n)&&e.open(t)>e.open(r)&&e.open(t)<=e.close(r)&&e.body(t)<e.body(r)&&e.body(r)<e.body(n)&&e.upper(t)>e.upper(n)}),U(`identicalThreeCrows`,`Identical Three Crows`,`Ident Crows`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.black(r)&&e.black(t)&&e.close(r)<e.close(n)&&e.close(t)<e.close(r)&&e.same(e.open(r),e.close(n),n)&&e.same(e.open(t),e.close(r),n)&&e.lower(n)<=e.body(n)*.25&&e.lower(r)<=e.body(r)*.25&&e.lower(t)<=e.body(t)*.25})],Gl=[U(`bullishThreeLineStrike`,`Bullish Three-Line Strike`,`Strike`,`bullish`,`continuation`,4,`up`,(e,t)=>{let n=t-3;return e.white(n)&&e.white(n+1)&&e.white(n+2)&&Hl(e,n,n+2,!1)&&e.open(n+1)>=e.open(n)&&e.open(n+1)<=e.close(n)&&e.open(n+2)>=e.open(n+1)&&e.open(n+2)<=e.close(n+1)&&e.black(t)&&e.open(t)>e.close(n+2)&&e.close(t)<e.open(n)}),U(`bearishThreeLineStrike`,`Bearish Three-Line Strike`,`Strike`,`bearish`,`continuation`,4,`down`,(e,t)=>{let n=t-3;return e.black(n)&&e.black(n+1)&&e.black(n+2)&&Hl(e,n,n+2,!0)&&e.open(n+1)<=e.open(n)&&e.open(n+1)>=e.close(n)&&e.open(n+2)<=e.open(n+1)&&e.open(n+2)>=e.close(n+1)&&e.white(t)&&e.open(t)<e.close(n+2)&&e.close(t)>e.open(n)}),U(`risingThreeMethods`,`Rising Three Methods`,`Rising 3`,`bullish`,`continuation`,5,`up`,(e,t)=>{let n=t-4;return e.white(n)&&e.long(n,n)&&Ul(e,n,n+1,n+3,!0)&&Hl(e,n+1,n+3,!0)&&e.white(t)&&e.long(t,n)&&e.open(t)>e.close(t-1)&&e.close(t)>e.close(n)}),U(`fallingThreeMethods`,`Falling Three Methods`,`Falling 3`,`bearish`,`continuation`,5,`down`,(e,t)=>{let n=t-4;return e.black(n)&&e.long(n,n)&&Ul(e,n,n+1,n+3,!1)&&Hl(e,n+1,n+3,!1)&&e.black(t)&&e.long(t,n)&&e.open(t)<e.close(t-1)&&e.close(t)<e.close(n)}),U(`matHold`,`Mat Hold`,`Mat Hold`,`bullish`,`continuation`,5,`up`,(e,t)=>{let n=t-4;if(!(e.white(n)&&e.long(n,n)&&e.black(n+1)&&e.short(n+1,n)&&e.bodyGapUp(n,n+1)))return!1;for(let t=n+1;t<=n+3;t++)if(e.long(t,n)||e.bodyBottom(t)<e.mid(n))return!1;let r=Math.max(e.high(n+1),e.high(n+2),e.high(n+3));return e.close(n+3)<e.close(n+1)&&e.white(t)&&e.open(t)>e.close(t-1)&&e.close(t)>r}),U(`bullishBreakaway`,`Bullish Breakaway`,`Breakaway`,`bullish`,`reversal`,5,`down`,(e,t)=>{let n=t-4;return e.black(n)&&e.long(n,n)&&e.black(n+1)&&e.bodyGapDown(n,n+1)&&e.close(n+2)<e.close(n+1)&&e.close(n+3)<e.close(n+2)&&e.black(n+3)&&e.white(t)&&e.close(t)>e.open(n+1)&&e.close(t)<e.close(n)}),U(`bearishBreakaway`,`Bearish Breakaway`,`Breakaway`,`bearish`,`reversal`,5,`up`,(e,t)=>{let n=t-4;return e.white(n)&&e.long(n,n)&&e.white(n+1)&&e.bodyGapUp(n,n+1)&&e.close(n+2)>e.close(n+1)&&e.close(n+3)>e.close(n+2)&&e.white(n+3)&&e.black(t)&&e.close(t)<e.open(n+1)&&e.close(t)>e.close(n)}),U(`concealingBabySwallow`,`Concealing Baby Swallow`,`Swallow`,`bullish`,`reversal`,4,`down`,(e,t)=>{let n=t-3;return e.black(n)&&e.marubozu(n,n)&&e.black(n+1)&&e.marubozu(n+1,n)&&e.black(n+2)&&e.open(n+2)<e.close(n+1)&&e.high(n+2)>e.close(n+1)&&e.black(t)&&e.open(t)>e.high(n+2)&&e.close(t)<e.low(n+2)}),U(`ladderBottom`,`Ladder Bottom`,`Ladder`,`bullish`,`reversal`,5,`down`,(e,t)=>{let n=t-4;for(let t=n;t<=n+3;t++)if(!e.black(t))return!1;for(let t=n+1;t<=n+2;t++)if(e.open(t)>=e.open(t-1)||e.close(t)>=e.close(t-1))return!1;return e.upper(n+3)>e.body(n+3)&&e.white(t)&&e.open(t)>e.open(n+3)&&e.close(t)>e.high(n+3)})],Kl=[...Rl,...zl,...Wl,...Gl],ql=Kl.map(e=>e.info);function Jl(e){let t=e.trendPeriod;return t!==void 0&&Number.isFinite(t)?Math.max(2,Math.floor(t)):10}function Yl(e){if(!e.patterns)return Kl;let t=new Set(e.patterns);return Kl.filter(e=>t.has(e.info.id))}function Xl(e,t,n){let r=[];for(let i of n){let n=t-i.info.bars+1;n<0||i.trend&&e.trendBefore(n)!==i.trend||i.test(e,t)&&r.push(i)}return r}function Zl(e,t={}){let n=new Fl(e,Jl(t)),r=Yl(t),i=[],a=t.from!==void 0&&Number.isFinite(t.from)?Math.max(0,Math.floor(t.from)):0;for(let t=a;t<e.length;t++)for(let a of Xl(n,t,r))i.push({index:t,time:e[t].time,pattern:a.info});return i}function Ql(e={}){return Yl(e)}var $l=6,eu=4,tu=12,nu=class extends B{descriptor={id:`candlepatterns`,name:`Candlestick Patterns`,placement:`overlay`,defaultConfig:{trendPeriod:10,reversal:1,continuation:1,indecision:0},shortName:`Patterns`,inputs:{trendPeriod:{kind:`int`,min:2},reversal:{kind:`int`,min:0,max:1},continuation:{kind:`int`,min:0,max:1},indecision:{kind:`int`,min:0,max:1}},plots:[{key:`bull`,title:`Bullish`,color:3,kind:`dots`},{key:`bear`,title:`Bearish`,color:4,kind:`dots`},{key:`neutral`,title:`Indecision`,color:1,kind:`dots`}]};read(e){let t=new Set;return H(e,`reversal`,1,0)>=1&&t.add(`reversal`),H(e,`continuation`,1,0)>=1&&t.add(`continuation`),H(e,`indecision`,0,0)>=1&&t.add(`indecision`),{trendPeriod:H(e,`trendPeriod`,10,2),defs:Ql().filter(e=>t.has(e.info.kind))}}pointAt(e,t,{trendPeriod:n,defs:r}){let i=Xl(new Fl(e,n),t,r);if(i.length===0)return null;let a=i[0];for(let e of i)e.info.bars>=a.info.bars&&(a=e);let o=e[t],s={code:ql.indexOf(a.info),count:i.length};return a.info.direction===`bullish`?s.bull=o.low:a.info.direction===`bearish`?s.bear=o.high:s.neutral=o.high,s}render(t,n,r,i){let a=n.series;if(!a)return;let o=Math.max(0,Math.floor(r.visibleRange.from)),s=Math.min(a.length-1,Math.ceil(r.visibleRange.to)),c=r.barWidth+r.barSpacing>=tu,{chartRect:l}=r,u=l.y+10,d=l.y+l.height-10,f=e=>i.plots?.[e]?.visible!==!1;t.save(),t.globalAlpha=i.opacity,t.font=`10px sans-serif`,t.textAlign=`center`;let p=-1/0,m=-1/0;for(let n=o;n<=s;n++){let o=a[n];if(!o)continue;let s=e.b(n,r),l=ql[o.code??-1]?.short??``;if(o.bull!==void 0&&f(`bull`)){let n=e.T(o.bull,r)+eu;t.fillStyle=i.colors[3]??i.colors[0],ru(t,s,n,`up`),c&&l&&(m=iu(t,l,s,Math.min(d,n+$l+2),`top`,m))}else if(o.bear!==void 0&&f(`bear`)){let n=e.T(o.bear,r)-eu;t.fillStyle=i.colors[4]??i.colors[0],ru(t,s,n,`down`),c&&l&&(p=iu(t,l,s,Math.max(u,n-$l-2),`bottom`,p))}else if(o.neutral!==void 0&&f(`neutral`)){let n=e.T(o.neutral,r)-eu-$l/2;t.fillStyle=i.colors[1]??i.colors[0],t.beginPath(),t.arc(s,n,$l/2-1,0,Math.PI*2),t.fill(),c&&l&&(p=iu(t,l,s,Math.max(u,n-$l/2-2),`bottom`,p))}}t.restore()}};function ru(e,t,n,r){let i=$l/2;e.beginPath(),r===`up`?(e.moveTo(t,n),e.lineTo(t-i,n+$l),e.lineTo(t+i,n+$l)):(e.moveTo(t,n),e.lineTo(t-i,n-$l),e.lineTo(t+i,n-$l)),e.closePath(),e.fill()}function iu(e,t,n,r,i,a){let o=e.measureText(t).width/2;return n-o<a+2?a:(e.textBaseline=i,e.fillText(t,n,r),n+o)}var au=500,ou=class extends I{descriptor={id:`machannel`,name:`Moving Average Channel`,placement:`overlay`,defaultConfig:{upperLength:20,lowerLength:20,upperOffset:0,lowerOffset:0},shortName:`MA Channel`,inputs:{upperLength:{kind:`int`,min:1},lowerLength:{kind:`int`,min:1},upperOffset:{kind:`int`,min:-au,max:au},lowerOffset:{kind:`int`,min:-au,max:au}},fills:[{between:[`upper`,`lower`],color:0,opacity:.08}],plots:[{key:`upper`,title:`Upper`,color:0},{key:`lower`,title:`Lower`,color:1}]};calculate(e,t){let n=cu(Ia(e.map(e=>e.high),H(t,`upperLength`,20,1)),su(t,`upperOffset`)),r=cu(Ia(e.map(e=>e.low),H(t,`lowerLength`,20,1)),su(t,`lowerOffset`));return R(e,n.map((e,t)=>{let n=r[t];return e===void 0&&n===void 0?null:{...e===void 0?{}:{upper:e},...n===void 0?{}:{lower:n}}}))}};function su(e,t){let n=Number(e.params[t]??0);return Number.isFinite(n)?Math.max(-au,Math.min(au,Math.round(n))):0}function cu(e,t){return e.map((n,r)=>e[r-t])}var lu=500,uu=class extends B{descriptor={id:`hamming`,name:`Moving Average Hamming`,placement:`overlay`,defaultConfig:{period:10,source:`close`},shortName:`HMA (Hamming)`,inputs:{period:{kind:`int`,min:2,max:lu},source:{source:!0}},plots:[{key:`value`,title:`MA`,color:0}]};read(e){let t=Math.min(lu,H(e,`period`,10,2)),n=Array.from({length:t},(e,n)=>.54-.46*Math.cos(2*Math.PI*n/(t-1)));return{weights:n,total:n.reduce((e,t)=>e+t,0)}}pointAt(e,t,{weights:n,total:r}){let i=t-n.length+1;if(i<0)return null;let a=0;for(let t=0;t<n.length;t++)a+=n[t]*e[i+t].close;return{value:a/r}}},du=[`sma`,`ema`,`wma`];function fu(e,t,n){return e===`ema`?z(t,n):e===`wma`?Ra(t,n):Ia(t,n)}var pu=class extends I{calculate(e,t){let n=du.includes(t.params.type)?t.params.type:`sma`,r=Fa(e),i=this.lengths.map(([e,i])=>fu(n,r,H(t,e,i,1)));return R(e,e.map((e,t)=>{let n={};return i.forEach((e,r)=>{let i=e[t];i!==void 0&&(n[`ma${r+1}`]=i)}),Object.keys(n).length>0?n:null}))}},mu=class extends pu{lengths=[[`first`,20],[`second`,50]];descriptor={id:`madouble`,name:`Moving Average Double`,placement:`overlay`,defaultConfig:{first:20,second:50,type:`sma`,source:`close`},shortName:`MA x2`,inputs:{first:{kind:`int`,min:1},second:{kind:`int`,min:1},type:{options:du},source:{source:!0}},plots:[{key:`ma1`,title:`MA 1`,color:0},{key:`ma2`,title:`MA 2`,color:1}]}},hu=class extends pu{lengths=[[`first`,10],[`second`,20],[`third`,50]];descriptor={id:`matriple`,name:`Moving Average Triple`,placement:`overlay`,defaultConfig:{first:10,second:20,third:50,type:`sma`,source:`close`},shortName:`MA x3`,inputs:{first:{kind:`int`,min:1},second:{kind:`int`,min:1},third:{kind:`int`,min:1},type:{options:du},source:{source:!0}},plots:[{key:`ma1`,title:`MA 1`,color:0},{key:`ma2`,title:`MA 2`,color:1},{key:`ma3`,title:`MA 3`,color:2}]}},gu=class extends I{descriptor={id:`volindex`,name:`Volatility Index`,placement:`overlay`,defaultConfig:{period:7,mult:3},shortName:`VI`,inputs:{period:{kind:`int`,min:1},mult:{kind:`number`,label:`ATR multiple`,min:.1,step:.1}},plots:[{key:`sar`,title:`Stop`,color:0,kind:`dots`,tone:{field:`long`},downColor:1}]};calculate(e,t){let n=H(t,`period`,7,1),r=Math.max(.1,V(t,`mult`,3)),i=za(Va(e),n),a=Array(e.length).fill(null),o=null,s=0;for(let t=0;t<e.length;t++){let n=i[t];if(n===void 0)continue;let c=e[t].close,l=n*r;o===null?(o=c>=e[0].close,s=c):o?(s=Math.max(s,c),c<s-l&&(o=!1,s=c)):(s=Math.min(s,c),c>s+l&&(o=!0,s=c)),a[t]={sar:o?s-l:s+l,long:+!!o}}return R(e,a)}},_u=class extends I{descriptor={id:`asi`,name:`Accumulative Swing Index`,placement:`panel`,defaultConfig:{limit:10},shortName:`ASI`,inputs:{limit:{kind:`number`,label:`Limit move`,min:1e-4,step:.1}},plots:[{key:`value`,title:`ASI`,color:0}],scale:{zero:!0}};calculate(e,t){let n=Math.max(1e-9,V(t,`limit`,10)),r=Array(e.length).fill(null),i=0;for(let t=1;t<e.length;t++)i+=vu(e[t-1],e[t],n),r[t]={value:i};return R(e,r)}};function vu(e,t,n){let r=Math.abs(t.high-e.close),i=Math.abs(t.low-e.close),a=t.high-t.low,o=Math.abs(e.close-e.open),s;return s=r>=i&&r>=a?r-.5*i+.25*o:i>=r&&i>=a?i-.5*r+.25*o:a+.25*o,s===0?0:50*(t.close-e.close+.5*(t.close-t.open)+.25*(e.close-e.open))/s*(Math.max(r,i)/n)}var yu=class extends B{descriptor={id:`advdecline`,name:`Advance/Decline`,placement:`panel`,defaultConfig:{length:10},shortName:`A/D Ratio`,inputs:{length:{kind:`int`,min:1}},plots:[{key:`value`,title:`Ratio`,color:0}],scale:{min:0}};read(e){return{length:H(e,`length`,10,1)}}pointAt(e,t,{length:n}){if(t<n-1)return null;let r=0,i=0;for(let a=t-n+1;a<=t;a++)e[a].close>e[a].open?r++:e[a].close<e[a].open&&i++;return{value:i===0?r:r/i}}},bu=class extends B{descriptor={id:`majority`,name:`Majority Rule`,placement:`panel`,defaultConfig:{period:14},shortName:`Majority`,inputs:{period:{kind:`int`,min:1}},plots:[{key:`value`,title:`Majority`,color:0}],scale:{min:0,max:100},levels:[50]};read(e){return{period:H(e,`period`,14,1)}}pointAt(e,t,{period:n}){if(t<n)return null;let r=0;for(let i=t-n+1;i<=t;i++)e[i].close>e[i-1].close&&r++;return{value:100*r/n}}},xu=34,Su=30,Cu=class extends I{descriptor={id:`chopzone`,name:`Chop Zone`,placement:`panel`,defaultConfig:{},shortName:`Chop Zone`,plots:[{key:`angle`,title:`Angle`,color:0,kind:`histogram`}],scale:{zero:!0}};calculate(e,t){let n=z(Fa(e),xu),r=Array(e.length).fill(null);for(let t=1;t<e.length;t++){let i=n[t],a=n[t-1],o=Ka(e,t,Su),s=qa(e,t,Su);if(i===void 0||a===void 0||o===void 0||s===void 0||o===s)continue;let c=e[t],l=(c.high+c.low+c.close)/3;if(!(l>0&&s>0))continue;let u=(i-a)/l*(25/(o-s)*s);r[t]={angle:Math.atan(u)*180/Math.PI}}return R(e,r)}render(t,n,r,i){if(i.plots?.angle?.visible===!1)return;let a=n.series;if(!a)return;let{from:o,to:s}=r.visibleRange,c=e.T(0,r),l=[];for(let t=o;t<=s&&t<a.length;t++){let n=a[t]?.angle;n!==void 0&&l.push({x:e.b(t,r),y:e.T(n,r),baseY:c,color:wu(n)})}this.drawHistogram(t,l,Math.max(1,r.barWidth))}};function wu(e){return e>=5?`#26C6DA`:e>=3.57?`#43A047`:e>=2.14?`#A5D6A7`:e>=.71?`#009688`:e<=-5?`#D50000`:e<=-3.57?`#E91E63`:e<=-2.14?`#FF6D00`:e<=-.71?`#FFB74D`:`#FDD835`}var Tu=class extends I{descriptor={id:`smiergodic`,name:`SMI Ergodic`,placement:`panel`,defaultConfig:{short:5,long:20,signal:5,source:`close`},shortName:`SMIIO`,inputs:{short:{kind:`int`,min:1},long:{kind:`int`,min:1},signal:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`oscillator`,title:`Oscillator`,color:2,kind:`histogram`,tone:`sign`,downColor:3},{key:`indicator`,title:`Indicator`,color:0},{key:`signal`,title:`Signal`,color:1}],scale:{zero:!0}};calculate(e,t){let n=H(t,`short`,5,1),r=H(t,`long`,20,1),i=e.map((t,n)=>n===0?void 0:t.close-e[n-1].close),a=z(z(i,r),n),o=z(z(i.map(e=>e===void 0?void 0:Math.abs(e)),r),n),s=a.map((e,t)=>e===void 0||!o[t]?void 0:e/o[t]),c=z(s,H(t,`signal`,5,1));return R(e,s.map((e,t)=>{if(e===void 0)return null;let n=c[t];return n===void 0?{indicator:e}:{indicator:e,signal:n,oscillator:e-n}}))}},Eu=class extends I{descriptor={id:`po`,name:`Price Oscillator`,placement:`panel`,defaultConfig:{short:10,long:21,source:`close`},shortName:`PO`,inputs:{short:{kind:`int`,min:1},long:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`value`,title:`PO`,color:0}],scale:{zero:!0}};calculate(e,t){let n=Fa(e),r=Ia(n,H(t,`short`,10,1)),i=Ia(n,H(t,`long`,21,1));return R(e,Wa(r.map((e,t)=>e===void 0||i[t]===void 0?void 0:e-i[t])))}},Du=e=>({period:H(e,`period`,10,1),annual:Math.max(1,V(e,`annual`,365))}),Ou={period:{kind:`int`,min:1},annual:{kind:`number`,label:`Bars per year`,min:1}},ku=class extends B{descriptor={id:`volohlc`,name:`Volatility O-H-L-C`,placement:`panel`,defaultConfig:{period:10,annual:365},shortName:`Vol OHLC`,inputs:Ou,plots:[{key:`value`,title:`Volatility`,color:0}],scale:{min:0}};read(e){return Du(e)}pointAt(e,t,{period:n,annual:r}){if(t<n-1)return null;let i=0;for(let r=t-n+1;r<=t;r++){let{open:t,high:n,low:a,close:o}=e[r];if(!(t>0&&n>0&&a>0&&o>0))return null;i+=.5*Math.log(n/a)**2-(2*Math.LN2-1)*Math.log(o/t)**2}return{value:100*Math.sqrt(Math.max(0,i/n*r))}}},Au=class extends B{descriptor={id:`volzt`,name:`Volatility Zero Trend Close-to-Close`,placement:`panel`,defaultConfig:{period:10,annual:365},shortName:`Vol ZT`,inputs:Ou,plots:[{key:`value`,title:`Volatility`,color:0}],scale:{min:0}};read(e){return Du(e)}pointAt(e,t,{period:n,annual:r}){if(t<n)return null;let i=0;for(let r=t-n+1;r<=t;r++){let t=e[r-1].close,n=e[r].close;if(!(t>0&&n>0))return null;i+=Math.log(n/t)**2}return{value:100*Math.sqrt(i/n*r)}}},ju=[()=>new Fo,()=>new Io,()=>new Lo,()=>new Uo,()=>new Ko,()=>new qo,()=>new Jo,()=>new Yo,()=>new Xo,()=>new Qo,()=>new es,()=>new ts,()=>new ns,()=>new rs,()=>new os,()=>new ss,()=>new cs,()=>new ls,()=>new ds,()=>new fs,()=>new ps,()=>new _s,()=>new bs,()=>new xs,()=>new Ss,()=>new Cs,()=>new ws,()=>new Ts,()=>new Es,()=>new Ds,()=>new Os,()=>new ks,()=>new As,()=>new js,()=>new Ms,()=>new vc,()=>new xc,()=>new Sc,()=>new Cc,()=>new vs,()=>new ys,()=>new Ns,()=>new Ps,()=>new Fs,()=>new Is,()=>new Rs,()=>new zs,()=>new Vs,()=>new Hs,()=>new Gs,()=>new Ks,()=>new Js,()=>new Ys,()=>new Xs,()=>new Zs,()=>new Qs,()=>new $s,()=>new ec,()=>new nc,()=>new rc,()=>new ic,()=>new ac,()=>new oc,()=>new sc,()=>new uc,()=>new fc,()=>new mc,()=>new hc,()=>new gc,()=>new _c,()=>new wc,()=>new Tc,()=>new Ec,()=>new Dc,()=>new Oc,()=>new kc,()=>new Mc,()=>new Pc,()=>new Fc,()=>new Rc,()=>new zc,()=>new Bc,()=>new Vc,()=>new Hc,()=>new Wc,()=>new qc,()=>new Jc,()=>new Yc,()=>new Xc,()=>new Zc,()=>new Qc,()=>new $c,()=>new el,()=>new rl,()=>new il,()=>new ol,()=>new sl,()=>new cl,()=>new ou,()=>new uu,()=>new mu,()=>new hu,()=>new gu,()=>new _u,()=>new yu,()=>new bu,()=>new Cu,()=>new Tu,()=>new Eu,()=>new ku,()=>new Au,()=>new ul,()=>new dl,()=>new fl,()=>new pl,()=>new ml,()=>new hl,()=>new gl,()=>new _l,()=>new yl,()=>new Sl,()=>new Cl,()=>new wl,()=>new Tl,()=>new El,()=>new Dl,()=>new Ol,()=>new kl,()=>new Al,()=>new jl,()=>new ll,()=>new Ml,()=>new Nl,()=>new nu];function Mu(e){for(let t of ju){let n=t();Pa.add(n),e.register(n)}}var Nu=[`movingAverages`,`trend`,`oscillators`,`volatility`,`volume`,`bands`,`patterns`,`other`],Pu=new Map(Object.entries({movingAverages:[`sma`,`ema`,`wma`,`vwma`,`hma`,`tema`,`dema`,`smma`,`alma`,`kama`,`lsma`,`mcginley`,`mtfma`,`macross`,`gmma`,`maribbon`,`hamming`,`madouble`,`matriple`,`rainbow`,`alligator`,`tsf`],trend:[`ichimoku`,`psar`,`supertrend`,`chandelier`,`cks`,`volindex`,`adx`,`aroon`,`vortex`,`chop`,`chopzone`,`vhf`,`trendstrength`,`lrslope`,`rsquared`,`rwi`,`majority`,`asi`],oscillators:`rsi.macd.stochastic.williamsR.cci.roc.tsi.ao.uo.crsi.coppock.kst.elderray.stc.fisher.dpo.bop.cmo.trix.rvi.stochrsi.ppo.ac.rmi.disparity.qstick.pgo.bbpb.mom.smi.smiergodic.po.psy.newpsy.sonar.binarywave.sroc.abratio.advdecline`.split(`.`),volatility:[`atr`,`stddev`,`chaikinvol`,`bbw`,`hv`,`ulcer`,`rvix`,`stderror`,`adr`,`volohlc`,`volzt`,`sigma`,`tr`,`massindex`],volume:[`vwap`,`avwap`,`svwap`,`volumeProfile`,`obv`,`mfi`,`cmf`,`ad`,`vroc`,`chaikinOsc`,`voldelta`,`fi`,`kvo`,`emv`,`pvt`,`wad`,`vo`,`netvolume`,`vr`,`nvi`,`pvi`,`iii`,`volpct`,`volchange`,`tradevalue`],bands:[`bb`,`keltner`,`donchian`,`envelope`,`lrc`,`seb`,`machannel`],patterns:[`pivots`,`zigzag`,`fractals`,`candlepatterns`,`demark`,`avgprice`,`medprice`,`typprice`,`wclose`]}).flatMap(([e,t])=>t.map(t=>[t,e])));function Fu(e){return e.category??Pu.get(e.id)??`other`}var Iu=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,Lu=1,Ru=.1;function zu(e,t){return t?.kind?t.kind:t?.source?`source`:t?.options?`choice`:typeof e==`boolean`?`boolean`:typeof e==`number`?`number`:typeof e==`string`&&Iu.test(e)?`color`:`text`}function Bu(e){return Object.entries(e.defaultConfig).map(([t,n])=>{let r=e.inputs?.[t],i=zu(n,r),a={name:t,kind:i,default:n};return r?.label!==void 0&&(a.label=r.label),r?.min!==void 0&&(a.min=r.min),r?.max!==void 0&&(a.max=r.max),i===`int`&&(a.step=r?.step??Lu),i===`number`&&(a.step=r?.step??(Number.isInteger(n)?Lu:Ru)),i===`choice`&&r?.options&&(a.options=r.options),a})}function Vu(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.requestId==`number`?t.type===`result`||t.type===`pong`||t.type===`error`:!1}var Hu=class{worker;fallbackPlugins;timeoutMs;nextRequestId=1;pending=new Map;messageHandler;constructor(e,t={}){this.worker=e,this.fallbackPlugins=t.fallbackPlugins??new Map,this.timeoutMs=t.timeoutMs??3e4,this.messageHandler=e=>this.handleMessage(e),this.worker&&(this.worker.addEventListener(`message`,this.messageHandler),this.worker.addEventListener(`error`,this.messageHandler))}hasWorker(){return this.worker!==null}registerFallbackPlugin(e){this.fallbackPlugins.set(e.descriptor.id,e)}async calculate(e,t,n){if(!this.worker){let r=this.fallbackPlugins.get(e);if(!r)throw Error(`Unknown indicator: ${e}`);return r.calculate(n,t)}let r=this.nextRequestId++,i=co(n),a={type:`calculate`,bars:i,jobs:[{requestId:r,indicatorId:e,config:t}]},o=i.time.slice();return new Promise((t,n)=>{let s={resolve:t,reject:n,timer:null,times:o};this.timeoutMs>0&&(s.timer=setTimeout(()=>{this.pending.delete(r),n(Error(`Indicator worker timeout (${this.timeoutMs}ms): ${e}`))},this.timeoutMs)),this.pending.set(r,s),this.worker.postMessage(a,uo(i))})}ping(){if(!this.worker)return Promise.resolve();let e=this.nextRequestId++;return new Promise((t,n)=>{let r={resolve:()=>t(),reject:n,timer:this.timeoutMs>0?setTimeout(()=>{this.pending.delete(e),n(Error(`Indicator worker ping timeout`))},this.timeoutMs):null};this.pending.set(e,r),this.worker.postMessage({type:`ping`,requestId:e})})}terminate(){this.worker&&=(this.worker.removeEventListener(`message`,this.messageHandler),this.worker.removeEventListener(`error`,this.messageHandler),this.worker.terminate(),null);for(let e of this.pending.values())e.timer&&clearTimeout(e.timer),e.reject(Error(`Indicator worker terminated`));this.pending.clear()}handleMessage(e){let t=e.data;if(t!==void 0){if(!Vu(t))return;this.dispatchResponse(t);return}let n=e.message??`Indicator worker error`;for(let[e,t]of this.pending)t.timer&&clearTimeout(t.timer),t.reject(Error(n)),this.pending.delete(e)}dispatchResponse(e){let t=this.pending.get(e.requestId);if(t){if(this.pending.delete(e.requestId),t.timer&&clearTimeout(t.timer),e.type===`error`){t.reject(Error(e.message));return}if(e.type===`pong`){t.resolve(void 0);return}t.resolve(bo(e.output,t.times??[]))}}};function Uu(){return typeof Worker>`u`?Promise.reject(Error(`Web Workers are not available here`)):Promise.resolve().then(()=>require(`./indicator.worker-g0us81yM.cjs`)).then(({default:e})=>new e({name:`tradecanvas-indicators`}))}function Wu(){if(typeof Worker>`u`)throw Error(`Web Workers are not available here`);return Uu()}var Gu=class{state=`starting`;worker=null;outbox=[];jobs=new Map;batch=null;nextId=1;pingId=0;onMessage=e=>this.receive(e.data);onError=e=>this.fail(Error(e.message||`Indicator worker error`));constructor(e){let t;try{t=e()}catch(e){this.fail(Ku(e));return}t instanceof Promise?t.then(e=>this.attach(e),e=>this.fail(Ku(e))):this.attach(t)}get usable(){return this.state===`starting`||this.state===`ready`}get ready(){return this.state===`ready`}submit(e,t){if(!this.usable)return null;let n=this.nextId++;this.jobs.set(n,{done:t,times:e.times});let{indicatorId:r,config:i,source:a,bars:o}=e;return this.batchFor(o).jobs.push({requestId:n,indicatorId:r,config:i,...a?{source:a}:{}}),n}batchFor(e){if(this.batch?.bars===e)return this.batch;this.sendBatch();let t={bars:e,jobs:[]};return this.batch=t,queueMicrotask(()=>{this.batch===t&&this.sendBatch()}),t}sendBatch(){let e=this.batch;this.batch=null;let t=e?.jobs.filter(e=>this.jobs.has(e.requestId))??[];!e||t.length===0||!this.usable||this.send({message:{type:`calculate`,bars:e.bars,jobs:t},transfer:uo(e.bars)})}cancel(e){let t=new Set(this.batch?.jobs.map(e=>e.requestId)),n=e.filter(e=>this.jobs.delete(e)&&!t.has(e));n.length>0&&this.usable&&this.send({message:{type:`cancel`,requestIds:n},transfer:[]})}terminate(){this.state=`closed`,this.jobs.clear(),this.batch=null,this.outbox=[],this.detach()}attach(e){if(!this.usable){e.terminate();return}this.worker=e,e.addEventListener(`message`,this.onMessage),e.addEventListener(`error`,this.onError),e.addEventListener(`messageerror`,this.onError),this.pingId=this.nextId++,e.postMessage({type:`ping`,requestId:this.pingId});let t=this.outbox;this.outbox=[];for(let n of t)e.postMessage(n.message,n.transfer)}send(e){this.worker?this.worker.postMessage(e.message,e.transfer):this.outbox.push(e)}receive(e){if(!Vu(e))return;if(e.type===`pong`){e.requestId===this.pingId&&this.state===`starting`&&(this.state=`ready`);return}let t=this.jobs.get(e.requestId);if(t){if(e.type===`result`){this.decode(e.requestId,t,e.output);return}this.jobs.delete(e.requestId),t.done(Error(e.message))}}decode(e,t,n){let r=new yo(n,t.times),i=()=>{if(this.jobs.get(e)===t){if(!r.step(5e4)){setTimeout(i,0);return}this.jobs.delete(e),t.done({output:r.output(),...n.state===void 0?{}:{state:wo(n.state)}})}};i()}fail(e){if(!this.usable)return;this.state=`failed`,this.outbox=[],this.detach(),this.batch=null;let t=[...this.jobs.values()];this.jobs.clear();for(let{done:n}of t)n(e)}detach(){let e=this.worker;e&&(this.worker=null,e.removeEventListener(`message`,this.onMessage),e.removeEventListener(`error`,this.onError),e.removeEventListener(`messageerror`,this.onError),e.terminate())}};function Ku(e){return e instanceof Error?e:Error(String(e))}var qu=class{client=null;holders=0;constructor(e=Wu){this.spawn=e}acquire(){let e=this.client??=new Gu(this.spawn);this.holders++;let t=!0;return{client:e,release:()=>{t&&(t=!1,this.holders--,this.holders===0&&this.client===e&&(e.terminate(),this.client=null))}}}},Ju=new qu,W={year:100,quarter:91,month:90,dayOfFive:81,day:80,hour12:73,hour6:72,hour3:71,hour:70,minute30:63,minute15:62,minute5:61,minute:60,within:50},Yu=[...new Set(Object.values(W))].sort((e,t)=>t-e),Xu=256;function Zu(e){return e>=W.year?`year`:e>=W.month?`month`:e>=W.day?`day`:`time`}function Qu(e,t){if(!e)return 0;if(t.year!==e.year)return W.year;if(t.month!==e.month)return t.month%3==1?W.quarter:W.month;if(t.day!==e.day)return t.day%5==0?W.dayOfFive:W.day;if(t.hours!==e.hours){let e=t.hours;return e%12==0?W.hour12:e%6==0?W.hour6:e%3==0?W.hour3:W.hour}if(t.minutes!==e.minutes){let e=t.minutes;return e%30==0?W.minute30:e%15==0?W.minute15:e%5==0?W.minute5:W.minute}return W.within}var $u=256,ed=1.25;function td(e){return e>1?Math.ceil(ed**Math.ceil(Math.log(e)/Math.log(ed)-1e-9)):1}var nd=class{weights=new Uint8Array;times=[];weighed=null;weighedFrom=null;revision=0;chosen=new Int32Array;chosenFor=null;marks(e,t){let n=e.length;if(n===0)return[];let r=td(t.gapBars),i=t.timesPastData?Math.max(n-1,Math.ceil(t.to)):n-1,a=i<=n-1?n:Math.ceil((i+1-n)/$u)*$u+n;this.weigh(e,t.tz,t.exchangeZone??null,a),this.choose(r,a);let o=Math.max(0,Math.floor(t.from)),s=Math.min(i,Math.ceil(t.to)),c=this.chosen,l=0,u=c.length;for(;l<u;){let e=l+u>>1;c[e]<o?l=e+1:u=e}let d=[];for(let e=l;e<c.length&&c[e]<=s;e++){let t=c[e];d.push({index:t,time:this.times[t],weight:this.weights[t]})}return d}weigh(n,r,i,a){let o=n.length,s=(0,t.barTimeUnit)(n),c=(0,t.barsAreDaily)(n)===!0,l=c?e=>(0,t.barDateParts)(e,r,i):e=>(0,t.timeParts)(e,r),u=this.weighed,d=0;if(u&&u.tz===r&&u.exchangeZone===i&&u.daily===c&&u.unit===s){let e=Math.min(u.bars,o),t=this.times;if(n===this.weighedFrom?.deref()&&o>=u.bars)d=e>0&&n[e-1].time*s===t[e-1]?e:0;else{for(;d<e&&n[d].time*s===t[d];)d++;d<e&&(d=0)}}if(this.weighedFrom?.deref()!==n&&(this.weighedFrom=new WeakRef(n)),u&&d===o&&u.bars===o&&u.extent===a)return;let f=d>0&&this.weights.length>=a,p=f?this.weights:new Uint8Array(a+(a>>3)),m=d>0?this.times:[];d>0&&!f&&p.set(this.weights.subarray(0,d)),m.length=d;let h=d>0?l(m[d-1]):null;for(let t=d;t<a;t++){let r=(t<o?n[t].time:e.y(t,n))*s,i=l(r);p[t]=t>0&&r===m[t-1]?0:Qu(h,i),m[t]=r,h=i}this.weights=p,this.times=m,this.weighed={bars:o,tz:r,exchangeZone:i,daily:c,extent:a,unit:s},this.revision++}choose(e,t){let n=this.chosenFor;if(n&&n.gapBars===e&&n.extent===t&&n.revision===this.revision)return;let r=this.weights,i=new Uint8Array(t),a=[],o=new Int32Array(Xu+1);for(let e=0;e<t;e++)o[r[e]+1]++;for(let e=1;e<=Xu;e++)o[e]+=o[e-1];let s=new Int32Array(t),c=o.slice(0,Xu);for(let e=0;e<t;e++)s[c[r[e]]++]=e;for(let n of Yu)for(let r=o[n];r<o[n+1];r++){let n=s[r];if(i[n])continue;a.push(n);let o=Math.max(0,n-e+1),c=Math.min(t-1,n+e-1);for(let e=o;e<=c;e++)i[e]=1}this.chosen=Int32Array.from(a).sort(),this.chosenFor={gapBars:e,extent:t,revision:this.revision}}},rd=e=>e<10?`0`+e:``+e,id=8,ad=new Map;function od(e){let t=ad.get(e);if(!t){let n;try{n=new Intl.DateTimeFormat(e,{month:`short`,timeZone:`UTC`})}catch{n=new Intl.DateTimeFormat(`en-US`,{month:`short`,timeZone:`UTC`})}t=Array.from({length:12},(e,t)=>n.format(Date.UTC(2e3,t,15))),ad.set(e,t)}return t}var sd=class{tz=null;exchangeZone=null;timeFormatter=null;timesPastData=!0;locale=`en-US`;columns=[];marker=new nd;setLocale(e){this.locale=e}setTimezoneOffset(e){this.tz=e}setExchangeTimeZone(e){this.exchangeZone=e}setTimeFormatter(e){this.timeFormatter=e}setTimesPastData(e){this.timesPastData=e}getTimesPastData(){return this.timesPastData}marks(e,t){let n=e.barWidth+e.barSpacing;if(!(n>0)||t.length===0)return[];let r=ai(t),i=this.marker.marks(r,{from:Math.floor(e.offset/n),to:Math.ceil((e.offset+e.chartRect.width)/n),gapBars:80/n,tz:this.tz,timesPastData:this.timesPastData,exchangeZone:this.exchangeZone});return r===t?i:ud(i)}label(e,n,r){if(this.timeFormatter)return this.timeFormatter(e.time,{kind:n,timeZone:this.tz});let i=r?(0,t.barDateParts)(e.time,this.tz,this.exchangeZone):(0,t.timeParts)(e.time,this.tz);if(n===`year`)return String(i.year);if(n===`month`)return od(this.locale)[i.month-1];if(n===`day`)return String(i.day);let a=`${rd(i.hours)}:${rd(i.minutes)}`;return e.weight===W.within?`${a}:${rd(new Date(e.time).getUTCSeconds())}`:a}labelColumns(){return this.columns}render(n,r,i,a,o){let{chartRect:s}=r,c=ai(a),l=o??s.y+s.height;n.strokeStyle=i.style?.axis.time.line??i.axisLine,n.lineWidth=1,n.globalAlpha=.65,n.beginPath(),n.moveTo(s.x,l+.5),n.lineTo(s.x+s.width,l+.5),n.stroke(),n.globalAlpha=1;let u=r.barWidth+r.barSpacing,d=-r.offset+s.x+r.barWidth/2,f=Math.ceil((r.offset+s.width)/u),p=(0,t.barTimeUnit)(c),m=c.length>0?e.y(Math.min(f,c.length-1),c):Date.now(),h=(0,t.tzLabel)(this.tz,m*p),g=`500 ${i.font.sizeSmall-1}px ${i.font.family}`,_=s.x+s.width-4;n.font=g;let v=_-n.measureText(h).width-8,y=`500 ${i.font.sizeSmall}px ${i.font.family}`,b=`600 ${i.font.sizeSmall}px ${i.font.family}`;n.textBaseline=`top`,n.textAlign=`center`,n.fillStyle=i.style?.axis.time.text??i.axisLabel;let x=[],S=this.marks(r,a).sort((e,t)=>t.weight-e.weight||e.index-t.index),C=(0,t.barsAreDaily)(c)===!0;for(let e of S){let t=e.index*u+d;if(t<s.x)continue;let r=Zu(e.weight),i=this.label(e,r,C);n.font=r===`year`?b:y;let a=n.measureText(i).width/2,o=Math.max(t,s.x+a);o+a>v||x.some(e=>o-a<e.right+id&&o+a+id>e.left)||(x.push({left:o-a,right:o+a}),n.fillText(i,o,l+7))}this.columns=x,n.font=g,n.textAlign=`right`,n.textBaseline=`top`,n.globalAlpha=.75,n.fillStyle=i.textSecondary,n.fillText(h,_,l+7),n.globalAlpha=1}},cd={year:3,month:2,day:1,time:0},ld=2;function ud(e){let t=[...new Set(e.map(e=>cd[Zu(e.weight)]))].sort((e,t)=>t-e);if(t.length<=ld)return e;let n=t[ld-1];return e.filter(e=>cd[Zu(e.weight)]>=n)}var dd={line:16,handle:22,alert:16,order:16,button:8,divider:12},fd=300,pd=24,md=class{last=null;tap(e,t=Date.now()){let n=this.last;return n&&t-n.at<=300&&Math.hypot(e.x-n.pos.x,e.y-n.pos.y)<=24?(this.last=null,!0):(this.last={pos:e,at:t},!1)}reset(){this.last=null}},hd=new Set,gd=null,_d=4,vd=8,yd=500,bd=800,xd={ctrl:!1,shift:!1,alt:!1};function Sd(){let e=typeof document<`u`?document.activeElement:null;return e instanceof Element&&e.closest(`[aria-modal="true"], [role="dialog"], [role="menu"]`)!==null}var Cd=class{panHandler=null;zoomHandler=null;crosshairHandler=null;axisDragHandler=null;alertDragHandler=null;axisViewportGetter=null;onAxisDoubleClick=null;onDrawingDoubleClick=null;onDrawingContextMenu=null;zoomArea=!1;idleCss=`crosshair`;showingIdle=!1;onChartContextMenu=null;priceAxisAdd=null;axisStrips=null;savedTouchAction=``;measureHandlers=null;measuring=!1;boxSelectHandlers=null;boxSelecting=!1;onAltClick=null;onEscape=null;onConfirm=null;onClick=null;markerAt=null;onMarkerHover=null;markerClickable=()=>!0;markerPos={x:0,y:0};hoveredMarker=null;downPos=null;downMoved=!1;pressForClick=!1;drawingManager=null;tradingManager=null;paneResizeHandler=null;viewportGetter=null;onOverlayDirty=null;boundHandlers=[];lastTouchDist=0;lastTouchMid={x:0,y:0};touchActive=!1;touchStartPos={x:0,y:0};longPressTimer=null;longPressed=!1;touchFallthrough=!1;touchDecided=!1;touchYielded=!1;taps=new md;pageScroll=!1;touchStartPrevented=!1;lastTouchAt=-1/0;pressPlacedPoint=!1;cachedRect=null;constructor(e){this.element=e}setOverlayDirtyCallback(e){this.onOverlayDirty=e}setPanHandler(e){this.panHandler=e,this.refreshTouchAction()}setZoomHandler(e){this.zoomHandler=e,this.refreshTouchAction()}setCrosshairHandler(e){this.crosshairHandler=e}setIdleCursor(e){this.idleCss=e,this.showingIdle&&(this.element.style.cursor=e)}setAltClickHandler(e){this.onAltClick=e}setEscapeHandler(e){this.onEscape=e}setConfirmHandler(e){this.onConfirm=e}setSignalMarkerHitTest(e,t,n=()=>!0){this.markerAt=e,this.onMarkerHover=t,this.markerClickable=n,e||(this.hoveredMarker=null)}leaveMarker(){this.hoveredMarker!==null&&(this.hoveredMarker=null,this.onMarkerHover?.(null,this.markerPos))}setClickHandler(e){this.onClick=e}setBoxSelectHandlers(e){this.boxSelectHandlers=e}setMeasureHandlers(e){this.measureHandlers=e}setAxisDragHandler(e,t,n){this.axisDragHandler=e,this.axisViewportGetter=t,this.onAxisDoubleClick=n??null}setDrawingManager(e,t){this.drawingManager=e,this.viewportGetter=t}setChartContextMenu(e){this.onChartContextMenu=e}setPriceAxisAddButton(e,t){this.priceAxisAdd={button:e,onClick:t}}setZoomAreaMode(e){this.zoomArea=e}setDrawingContextMenu(e){this.onDrawingContextMenu=e}setDrawingDoubleClick(e){this.onDrawingDoubleClick=e}setAlertDragHandler(e){this.alertDragHandler=e}setTradingManager(e,t){this.tradingManager=e,this.viewportGetter=t}setAxisStrips(e){this.axisStrips=e}setPaneResizeHandler(e){this.paneResizeHandler=e}setPageScroll(e){this.pageScroll=e,this.refreshTouchAction()}refreshTouchAction(){hd.has(this.element)&&this.element.style.setProperty(`touch-action`,this.touchAction())}pageTakes(){let e=!this.panHandler,t=this.pageScroll||!this.panHandler;return{x:e,y:t,zoom:!this.zoomHandler,any:e||t}}touchAction(){let e=this.pageTakes();if(e.x&&e.y&&e.zoom)return`manipulation`;let t=[e.x&&`pan-x`,e.y&&`pan-y`,e.zoom&&`pinch-zoom`].filter(Boolean);return t.length>0?t.join(` `):`none`}attach(){let e=()=>this.viewportGetter?.()??null;hd.add(this.element),this.savedTouchAction=this.element.style.getPropertyValue(`touch-action`),this.element.style.setProperty(`touch-action`,this.touchAction());let t=e=>{let t=this.axisStrips?.()??null,n=t?.plot??this.axisViewportGetter?.()?.chartRect;if(!n)return null;let r=this.axisDragHandler!==null;if(e.y>(t?.timeAxisTop??n.y+n.height))return r?`time`:null;let i=e.y>=n.y&&e.y<=n.y+n.height;if(e.x>n.x+n.width)return i?r?`price`:null:`inert`;let a=t?.left;return a&&a.width>0&&e.x<n.x&&e.x>=n.x-a.width?i&&a.scales&&r?`price`:`inert`:null},n=e=>{let t=this.axisStrips?.()??null,n=t?.plot??this.axisViewportGetter?.()?.chartRect;if(!n)return`plot`;if(e.y>(t?.timeAxisTop??n.y+n.height))return`timeAxis`;let r=e.y>=n.y&&e.y<=n.y+n.height,i=t?.left,a=!!i&&i.width>0&&e.x<n.x&&e.x>=n.x-i.width;return e.x>n.x+n.width||a?r?`priceAxis`:`pane`:r?`plot`:`pane`},r=e=>{let t=(this.viewportGetter?.()??this.axisViewportGetter?.())?.chartRect;return t?{x:Math.max(t.x,Math.min(t.x+t.width,e.x)),y:Math.max(t.y,Math.min(t.y+t.height,e.y))}:e},i=()=>this.zoomArea?`zoom-in`:this.crosshairHandler&&this.crosshairHandler.getMode()!==`hidden`?this.idleCss:``,a=e=>{this.element.style.cursor!==e&&(this.element.style.cursor=e),this.showingIdle=e!==``&&e===this.idleCss},o=n=>{let r=t(n);if(r===`price`)return`ns-resize`;if(r===`time`)return`ew-resize`;if(r===`inert`)return`default`;let a=this.paneResizeHandler?.cursorAt(n);if(a)return a;if(this.alertDragHandler?.isOverAlert(n))return`ns-resize`;let o=e();return this.tradingManager?.isOverButton(n)?`pointer`:o&&this.tradingManager?.isOverDraggableLine(n,o)?`ns-resize`:this.zoomArea?`zoom-in`:(o?this.drawingManager?.hoverCursorAt(n,o):null)||(o&&this.priceAxisAdd?.button.hit(n,o)?`pointer`:i())},s=!1,c=``,l=e=>{if(!(e.buttons&1)){b(e);return}g(e)},u=()=>{s||(s=!0,this.leaveMarker(),c=document.documentElement.style.userSelect,document.documentElement.style.userSelect=`none`,document.addEventListener(`mousemove`,l))},d=()=>{s&&(s=!1,document.documentElement.style.userSelect=c,document.removeEventListener(`mousemove`,l))},f=e=>e===this.element||e instanceof HTMLCanvasElement,p=(n,r,o)=>{this.panHandler?.cancelMomentum();let s=e(),c=o===`mouse`,l=c?void 0:dd;this.pressPlacedPoint=!1,c||this.drawingManager?.setModifiers({ctrl:!1,shift:!1}),this.downPos=n,this.downMoved=!1,this.pressForClick=!1;let u=t(n);if(u===`inert`)return`inert`;if(u&&this.axisDragHandler)return this.axisDragHandler.begin(u,n),`taken`;if(this.paneResizeHandler?.tryBegin(n,l?.divider))return`taken`;let d=!!this.drawingManager?.getActiveTool()||!!this.tradingManager?.isBracketActive()||!!this.tradingManager?.isOrderDraftActive();return r.ctrl&&!d&&!this.zoomArea&&s&&this.drawingManager?.beginCopyDrag(n,s,l)?(c&&a(`copy`),`taken`):this.boxSelectHandlers&&(this.zoomArea||r.ctrl&&!d)?(this.boxSelecting=!0,this.boxSelectHandlers.begin(n),c&&a(i()),this.onOverlayDirty?.(!0),`taken`):r.shift&&this.measureHandlers&&!d&&!(s&&this.drawingManager?.hoverCursorAt(n,s))?(this.measuring=!0,this.measureHandlers.begin(n),this.onOverlayDirty?.(!0),`taken`):r.alt&&this.onAltClick?(this.onAltClick(n),`taken`):this.priceAxisAdd&&s&&!d&&this.priceAxisAdd.button.hit(n,s)&&!this.alertDragHandler?.isOverAlert(n)&&!this.tradingManager?.isOverButton(n)&&!this.tradingManager?.isOverDraggableLine(n,s)&&!this.drawingManager?.hoverCursorAt(n,s)?(this.priceAxisAdd.onClick(n),`menu`):this.tradingManager&&s&&this.tradingManager.onPointerDown(n,s,l)?(c&&a(this.tradingManager.isOverButton(n)?`pointer`:`ns-resize`),`taken`):this.drawingManager&&s&&this.drawingManager.onPointerDown(n,s,l)?(c&&this.drawingManager.isDragging()&&a(`grabbing`),this.pressPlacedPoint=!!this.drawingManager.getActiveTool(),d||this.drawingManager.isEraser()?`taken`:`drawing`):this.alertDragHandler?.tryBegin(n,l?.alert)?(this.onOverlayDirty?.(),`taken`):(this.pressForClick=!0,this.panHandler&&(this.panHandler.onPointerDown(n),c&&a(`grabbing`)),`pan`)},m=e=>{if(gd=this.element,e.button!==0||!f(e.target))return;u(),this.invalidateRect();let t={ctrl:e.ctrlKey||e.metaKey,shift:e.shiftKey,alt:e.altKey};this.drawingManager?.setModifiers({ctrl:t.ctrl,shift:t.shift}),p(this.getMousePos(e),t,`mouse`)===`menu`&&e.preventDefault()},h=e=>{if(!s){if(!f(e.target)){this.leaveMarker();return}g(e)}},g=e=>{let t=this.getMousePos(e);if(this.drawingManager?.setModifiers({ctrl:e.ctrlKey||e.metaKey,shift:e.shiftKey}),!s){let e=this.markerAt?.(t)??null;e!==this.hoveredMarker&&(this.hoveredMarker=e,this.onMarkerHover?.(e,t)),e&&(this.markerPos=t),a(e&&this.markerClickable()?`pointer`:o(t))}_(t,`mouse`,s)},_=(t,n,i,a=t)=>{let o=e();if(this.downPos&&!this.downMoved){let e=n===`mouse`?_d:vd;Math.hypot(t.x-this.downPos.x,t.y-this.downPos.y)>e&&(this.downMoved=!0)}if(this.axisDragHandler?.isActive()){this.axisDragHandler.move(t),n===`touch`&&this.onOverlayDirty?.();return}if(this.paneResizeHandler?.isActive()){this.paneResizeHandler.move(t),n===`touch`&&this.onOverlayDirty?.();return}if(this.alertDragHandler?.isActive()){this.alertDragHandler.move(r(t)),this.onOverlayDirty?.();return}if(this.measuring&&this.measureHandlers){this.measureHandlers.move(t),this.onOverlayDirty?.(!0);return}if(this.boxSelecting&&this.boxSelectHandlers){this.boxSelectHandlers.move(t),this.onOverlayDirty?.(!0);return}if(this.tradingManager&&o&&this.tradingManager.onPointerMove(i?r(t):t,o)){this.crosshairHandler?.onPointerMove(t),this.onOverlayDirty?.();return}if(this.drawingManager&&o&&this.drawingManager.onPointerMove(t,o)){this.crosshairHandler?.onPointerMove(t),this.onOverlayDirty?.();return}this.panHandler?.onPointerMove(a),this.crosshairHandler?.onPointerMove(t),this.onOverlayDirty?.(!i)},v=(t,n,r=!1)=>{let i=this.downPos,a=this.downMoved&&i!==null,o=this.pressPlacedPoint,s=this.pressForClick&&!this.downMoved&&i!==null&&!r;if(this.pressForClick=!1,this.pressPlacedPoint=!1,this.downPos=null,this.downMoved=!1,this.boxSelecting&&this.boxSelectHandlers)return this.boxSelecting=!1,r?this.boxSelectHandlers.cancel():this.boxSelectHandlers.end(),this.onOverlayDirty?.(!0),!1;if(this.axisDragHandler?.isActive())return this.axisDragHandler.end(),!1;if(this.paneResizeHandler?.isActive())return this.paneResizeHandler.end(),!1;if(this.alertDragHandler?.isActive())return this.alertDragHandler.end(),this.onOverlayDirty?.(),!1;if(this.measuring&&this.measureHandlers)return this.measuring=!1,this.measureHandlers.end(),this.onOverlayDirty?.(!0),!1;if(r?this.tradingManager?.cancelPointer():this.tradingManager?.onPointerUp(t??void 0))return!1;let c=e();return r&&o&&this.drawingManager?.takeBackPoint(),n===`touch`&&a&&!r&&t&&c&&this.drawingManager?.placeAt(t,c),this.drawingManager?.onPointerUp()?!1:(this.panHandler?.onPointerUp(),r&&this.panHandler?.cancelMomentum(),s&&this.onClick&&this.onClick(i),s)},y=(n,r)=>{let i=t(n);if(i){i!==`inert`&&this.onAxisDoubleClick?.(i);return}let a=e();if(!a||this.drawingManager?.justFinished())return;let o=this.drawingManager?.drawingAt(n,a,r);o&&this.onDrawingDoubleClick?.(o)},b=e=>{if(e.button!==0&&e.type===`mouseup`||!s)return;d();let t=this.getMousePos(e);a(o(t)),v(t,`mouse`)},x=e=>{y(this.getMousePos(e))},S=()=>{if(this.leaveMarker(),s){this.crosshairHandler?.onPointerLeave(),this.onOverlayDirty?.(!0);return}a(``),this.panHandler?.onPointerUp(),this.drawingManager?.onPointerUp(),this.drawingManager?.clearHover(),this.tradingManager?.onPointerUp(),this.alertDragHandler?.end(),this.paneResizeHandler?.end(),this.crosshairHandler?.onPointerLeave(),this.pressForClick=!1,this.downPos=null,this.onOverlayDirty?.()},C=e=>{if(!this.zoomHandler||this.pageScroll&&!e.ctrlKey)return;e.preventDefault();let t=this.getMousePos(e);this.zoomHandler.onWheel(e.deltaY,t)},w=e=>{(e.key===`Shift`||e.key===`Control`||e.key===`Meta`)&&this.drawingManager?.setModifiers({ctrl:e.ctrlKey||e.metaKey,shift:e.shiftKey})},T=()=>this.drawingManager?.setModifiers({ctrl:!1,shift:!1}),E=e=>{if(w(e),Sd())return;if(e.key===`Escape`&&this.boxSelecting&&this.boxSelectHandlers&&(this.boxSelecting=!1,this.boxSelectHandlers.cancel(),this.onOverlayDirty?.(!0)),e.key===`Escape`&&this.onEscape&&this.onEscape(),e.key===`Enter`&&this.onConfirm&&this.onConfirm()){e.preventDefault();return}if(e.key!==`Escape`&&!this.ownsShortcuts())return;let t=this.drawingManager?.isDragging()??!1;this.drawingManager?.onKeyDown(e.key,e.ctrlKey||e.metaKey,e.shiftKey)&&(e.preventDefault(),t&&e.key===`Escape`&&a(i()))},D=t=>{if(this.touchActive||Date.now()-this.lastTouchAt<bd){t.preventDefault();return}let r=e();if(!r)return;let i=this.getMousePos(t),a=this.onDrawingContextMenu&&!this.drawingManager?.getActiveTool()?this.drawingManager?.drawingAt(i,r):null;if(a){t.preventDefault(),this.onDrawingContextMenu?.(a,i);return}if(this.tradingManager?.onContextMenu(i,r)){t.preventDefault();return}this.onChartContextMenu?.(n(i),i)&&t.preventDefault()},O=e=>{if(gd=this.element,!(!this.touchActive&&!f(e.target))){if(this.lastTouchAt=Date.now(),this.invalidateRect(),e.touches.length===1){let t=this.getTouchPos(e.touches[0]);this.touchStartPos=t,this.longPressed=!1,this.touchYielded=!1,this.touchDecided=!1;let n=p(t,xd,`touch`);if(this.touchActive=!0,this.touchFallthrough=n===`pan`||n===`inert`,this.touchStartPrevented=!(this.touchFallthrough&&this.pageTakes().any),this.touchStartPrevented&&e.preventDefault(),n===`drawing`){k(t);return}if(n!==`pan`)return;this.onAltClick&&(this.clearLongPress(),this.longPressTimer=setTimeout(()=>{this.longPressTimer=null,this.longPressed=!0,this.pressForClick=!1,this.onAltClick?.(t),this.panHandler?.onPointerUp(),this.panHandler?.cancelMomentum(),this.onOverlayDirty?.(!0)},yd)),this.crosshairHandler?.onPointerMove(t),this.onOverlayDirty?.(!0)}else if(e.touches.length===2){if(this.clearLongPress(),this.touchActive&&!this.touchYielded&&this.lastTouchDist===0&&v(null,`touch`,!0),!this.zoomHandler&&!this.panHandler){this.touchActive=!1;return}e.cancelable&&e.preventDefault(),this.lastTouchDist=this.getTouchDistance(e.touches[0],e.touches[1]),this.lastTouchMid=this.getTouchMidpoint(e.touches[0],e.touches[1]),this.touchActive=!0,this.touchYielded=!1}}},k=t=>{this.onDrawingContextMenu&&(this.clearLongPress(),this.longPressTimer=setTimeout(()=>{this.longPressTimer=null;let n=e(),r=n?this.drawingManager?.drawingAt(t,n,dd.line):null;r&&(v(null,`touch`,!0),this.longPressed=!0,this.touchYielded=!0,this.crosshairHandler?.onPointerLeave(),this.onDrawingContextMenu?.(r,t),this.onOverlayDirty?.())},yd))},A=e=>{if(this.touchDecided)return!1;let t=e.x-this.touchStartPos.x,n=e.y-this.touchStartPos.y;if(Math.hypot(t,n)<=vd)return!1;this.touchDecided=!0;let r=this.pageTakes();return Math.abs(n)>=Math.abs(t)?r.y:r.x},j=e=>{if(!(!this.touchActive||this.touchYielded)){if(e.touches.length===1){let t=this.getTouchPos(e.touches[0]);if(this.lastTouchDist>0){e.cancelable&&e.preventDefault(),this.panHandler?.onPointerMove(this.pageScroll?{x:t.x,y:this.touchStartPos.y}:t),this.onOverlayDirty?.();return}if(this.longPressTimer&&Math.hypot(t.x-this.touchStartPos.x,t.y-this.touchStartPos.y)>vd&&this.clearLongPress(),this.touchFallthrough&&this.pageTakes().any){if(!this.touchDecided&&Math.hypot(t.x-this.touchStartPos.x,t.y-this.touchStartPos.y)<=vd)return;if(A(t)){this.touchYielded=!0,v(null,`touch`,!0),this.crosshairHandler?.onPointerLeave(),this.onOverlayDirty?.(!0);return}}e.cancelable&&e.preventDefault(),_(t,`touch`,!0,this.pageScroll?{x:t.x,y:this.touchStartPos.y}:t)}else if(e.touches.length===2){e.cancelable&&e.preventDefault();let t=this.getTouchDistance(e.touches[0],e.touches[1]),n=this.getTouchMidpoint(e.touches[0],e.touches[1]);this.lastTouchDist>0&&t>0&&this.zoomHandler?.onPinch(t/this.lastTouchDist,n);let r=this.lastTouchMid.x-n.x;Math.abs(r)>1&&(this.panHandler?.onPointerDown(this.lastTouchMid),this.panHandler?.onPointerMove({x:n.x,y:this.lastTouchMid.y})),this.lastTouchDist=t,this.lastTouchMid=n,this.onOverlayDirty?.()}}},ee=e=>{if(this.clearLongPress(),this.touchActive)if(this.lastTouchAt=Date.now(),e.touches.length===0){let t=e.changedTouches?.[0],n=t?this.getTouchPos(t):null,r=this.lastTouchDist>0,i=!r&&!this.longPressed&&!this.touchYielded&&this.downPos!==null&&!this.downMoved;this.touchYielded||(r?this.panHandler?.onPointerUp():v(n,`touch`),!this.touchStartPrevented&&e.cancelable&&e.preventDefault()),i&&n&&this.taps.tap(n)?y(n,dd.line):i||this.taps.reset(),this.crosshairHandler?.onPointerLeave(),this.touchActive=!1,this.touchYielded=!1,this.lastTouchDist=0,this.onOverlayDirty?.()}else if(e.touches.length===1&&!this.touchYielded){let t=this.getTouchPos(e.touches[0]);this.touchStartPos=t,this.panHandler?.onPointerDown(t)}else e.touches.length===2&&this.lastTouchDist>0&&(this.lastTouchDist=this.getTouchDistance(e.touches[0],e.touches[1]),this.lastTouchMid=this.getTouchMidpoint(e.touches[0],e.touches[1]))},te=()=>{this.clearLongPress(),this.touchActive&&(this.lastTouchAt=Date.now(),this.touchYielded||(this.lastTouchDist>0?(this.panHandler?.onPointerUp(),this.panHandler?.cancelMomentum()):v(null,`touch`,!0)),this.taps.reset(),this.crosshairHandler?.onPointerLeave(),this.touchActive=!1,this.touchYielded=!1,this.lastTouchDist=0,this.onOverlayDirty?.())},ne=()=>this.invalidateRect(),re=()=>this.invalidateRect(),ie=()=>this.invalidateRect(),ae=e=>{let t=e.target instanceof Node&&this.element.contains(e.target)&&f(e.target);(s||t)&&e.preventDefault()};this.element.addEventListener(`mousedown`,m),this.element.addEventListener(`mousemove`,h),document.addEventListener(`dragstart`,ae,!0),document.addEventListener(`mouseup`,b),this.element.addEventListener(`mouseleave`,S),this.element.addEventListener(`dblclick`,x),this.element.addEventListener(`wheel`,C,{passive:!1}),this.element.addEventListener(`contextmenu`,D),this.element.addEventListener(`touchstart`,O,{passive:!1}),this.element.addEventListener(`touchmove`,j,{passive:!1}),this.element.addEventListener(`touchend`,ee),this.element.addEventListener(`touchcancel`,te),document.addEventListener(`keydown`,E),document.addEventListener(`keyup`,w),window.addEventListener(`blur`,T),window.addEventListener(`resize`,ne),document.addEventListener(`scroll`,re,{capture:!0,passive:!0}),this.element.addEventListener(`mouseenter`,ie),this.boundHandlers.push(d,()=>this.element.removeEventListener(`mousedown`,m),()=>document.removeEventListener(`keyup`,w),()=>window.removeEventListener(`blur`,T),()=>document.removeEventListener(`dragstart`,ae,!0),()=>this.element.removeEventListener(`mousemove`,h),()=>document.removeEventListener(`mouseup`,b),()=>this.element.removeEventListener(`mouseleave`,S),()=>this.element.removeEventListener(`dblclick`,x),()=>this.element.removeEventListener(`wheel`,C),()=>this.element.removeEventListener(`contextmenu`,D),()=>this.element.removeEventListener(`touchstart`,O),()=>this.element.removeEventListener(`touchmove`,j),()=>this.element.removeEventListener(`touchend`,ee),()=>this.element.removeEventListener(`touchcancel`,te),()=>document.removeEventListener(`keydown`,E),()=>window.removeEventListener(`resize`,ne),()=>document.removeEventListener(`scroll`,re,{capture:!0}),()=>this.element.removeEventListener(`mouseenter`,ie))}detach(){hd.delete(this.element),this.savedTouchAction?this.element.style.setProperty(`touch-action`,this.savedTouchAction):this.element.style.removeProperty(`touch-action`),gd===this.element&&(gd=null);for(let e of this.boundHandlers)e();this.boundHandlers=[],this.cachedRect=null,this.clearLongPress()}clearLongPress(){this.longPressTimer&&=(clearTimeout(this.longPressTimer),null)}invalidateRect(){this.cachedRect=null}getRect(){return this.cachedRect||=this.element.getBoundingClientRect(),this.cachedRect}ownsShortcuts(){let e=document.activeElement;if(e&&(e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.tagName===`SELECT`||e.isContentEditable))return!1;for(let t of hd)if(e&&t.contains(e))return t===this.element;return gd===null||gd===this.element}getMousePos(e){let t=this.getRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}getTouchPos(e){let t=this.getRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}getTouchDistance(e,t){return Math.hypot(t.clientX-e.clientX,t.clientY-e.clientY)}getTouchMidpoint(e,t){let n=this.getRect();return{x:(e.clientX+t.clientX)/2-n.left,y:(e.clientY+t.clientY)/2-n.top}}},wd=16,Td=3,Ed=wd+Td,Dd=class{enabled=!1;setEnabled(e){this.enabled=e}isEnabled(){return this.enabled}hit(e,t){if(!this.enabled)return!1;let{x:n,y:r,width:i,height:a}=t.chartRect,o=n+i-wd-Td;return e.x>=o&&e.x<=n+i&&e.y>=r&&e.y<=r+a}render(e,t,n,r){if(!this.enabled||!r)return;let{x:i,y:a,width:o,height:s}=t.chartRect;if(r.y<a||r.y>a+s||r.x<i||r.x>i+o)return;let c=i+o-Td-wd/2,l=wd/2;e.fillStyle=n.background,e.strokeStyle=n.axisLabelBackground,e.lineWidth=1,e.beginPath(),e.arc(c,r.y,l-.5,0,Math.PI*2),e.fill(),e.stroke(),e.strokeStyle=n.text,e.lineWidth=1.5,e.beginPath(),e.moveTo(c-l*.45,r.y),e.lineTo(c+l*.45,r.y),e.moveTo(c,r.y-l*.45),e.lineTo(c,r.y+l*.45),e.stroke()}},Od=100,kd=50,Ad=.1,jd=60,Md=16;function Nd(){return typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches}var Pd=class{dragging=!1;lastX=0;lastY=0;samples=[];momentumId=0;callback;onStart;friction=.92;constructor(e,t){this.callback=e,this.onStart=t}isDragging(){return this.dragging}onPointerDown(e){this.dragging=!0,this.lastX=e.x,this.lastY=e.y,this.samples=[{t:Date.now(),x:e.x,y:e.y}],this.stopMomentum(),this.onStart?.()}onPointerMove(e){if(!this.dragging)return;let t=this.lastX-e.x,n=this.lastY-e.y;this.lastX=e.x,this.lastY=e.y;let r=Date.now();for(this.samples.push({t:r,x:e.x,y:e.y});this.samples.length>2&&r-this.samples[1].t>Od;)this.samples.shift();(t||n)&&this.callback(t,n)}onPointerUp(){if(!this.dragging)return;this.dragging=!1;let e=this.releaseVelocity(Date.now());this.samples=[],!Nd()&&e&&Math.hypot(e.x,e.y)>Ad&&this.startMomentum(e.x,e.y)}cancelMomentum(){this.stopMomentum()}releaseVelocity(e){let t=this.samples[this.samples.length-1];if(!t||e-t.t>kd)return null;let n=this.samples.find(e=>t.t-e.t<=Od)??this.samples[0],r=t.t-n.t;return r<=0?null:{x:(n.x-t.x)/r,y:(n.y-t.y)/r}}startMomentum(e,t){this.stopMomentum();let n=e*Md,r=t*Md,i=Math.hypot(n,r);i>jd&&(n*=jd/i,r*=jd/i);let a=null,o=e=>{let t=a===null?1:Math.min(4,Math.max(0,(e-a)/Md));a=e;let i=this.friction**t;if(n*=i,r*=i,Math.hypot(n,r)<.5){this.momentumId=0;return}this.callback(n*t,r*t),this.momentumId=requestAnimationFrame(o)};this.momentumId=requestAnimationFrame(o)}stopMomentum(){this.momentumId&&=(cancelAnimationFrame(this.momentumId),0)}},Fd=class{callback;sensitivity;pendingDelta=0;pendingScale=1;pendingCenterX=0;rafId=0;constructor(e,t=.001){this.callback=e,this.sensitivity=t}onWheel(e,t){this.pendingDelta+=-e*this.sensitivity,this.pendingCenterX=t.x,this.schedule()}onPinch(e,t){!(e>0)||!Number.isFinite(e)||(this.pendingScale*=e,this.pendingCenterX=t.x,this.schedule())}schedule(){this.rafId||=requestAnimationFrame(()=>{this.rafId=0;let e=(1+this.pendingDelta)*this.pendingScale-1,t=this.pendingCenterX;this.pendingDelta=0,this.pendingScale=1,this.callback(e,t)})}dispose(){this.rafId&&=(cancelAnimationFrame(this.rafId),0)}},Id=class{dragging=!1;axis=null;startPos={x:0,y:0};lastPos={x:0,y:0};moved=!1;threshold=3;sensitivity=.005;constructor(e,t){this.onPriceScale=e,this.onTimeScale=t}begin(e,t){this.dragging=!0,this.axis=e,this.startPos=t,this.lastPos=t,this.moved=!1}move(e){if(!this.dragging||!this.axis)return!1;let t=e.x-this.startPos.x,n=e.y-this.startPos.y;if(!this.moved&&Math.hypot(t,n)<this.threshold)return!1;if(this.moved=!0,this.axis===`price`){let t=e.y-this.lastPos.y,n=Math.exp(t*this.sensitivity);this.onPriceScale(n)}else{let t=e.x-this.lastPos.x,n=Math.exp(t*this.sensitivity);this.onTimeScale(n)}return this.lastPos=e,!0}end(){let e=this.dragging&&this.moved;return this.dragging=!1,this.axis=null,this.moved=!1,e}isActive(){return this.dragging}},Ld=class{draggingId=null;constructor(e,t){this.alerts=e,this.viewportGetter=t}isOverAlert(e){let t=this.viewportGetter();return t?this.alerts.getAlertAtPoint(e,t)!==null:!1}tryBegin(e,t){let n=this.viewportGetter();if(!n)return!1;let r=this.alerts.getAlertAtPoint(e,n,t);return r?(this.draggingId=r.id,!0):!1}move(t){if(this.draggingId===null)return;let n=this.viewportGetter();n&&this.alerts.updateAlertPrice(this.draggingId,e.M(t.y,n))}end(){this.draggingId=null}isActive(){return this.draggingId!==null}},Rd=class{state=null;layoutGetter=null;onResize=null;constructor(e=4){this.tolerance=e}configure(e,t){this.layoutGetter=e,this.onResize=t}hitTest(e,t,n=this.tolerance){for(let r of t.dividers)if(zd(e,r.rect,n)){let e=t.panels.find(e=>e.config.id===r.panelId);if(e)return{panelId:r.panelId,orientation:r.orientation,position:e.config.position,size:r.orientation===`horizontal`?e.rect.height:e.rect.width}}return null}cursorAt(e){let t=this.layoutGetter?.();if(!t)return null;let n=this.hitTest(e,t);return n?n.orientation===`horizontal`?`ns-resize`:`ew-resize`:null}tryBegin(e,t){let n=this.layoutGetter?.();if(!n)return!1;let r=this.hitTest(e,n,Math.max(t??0,this.tolerance));return r?(this.state={panelId:r.panelId,position:r.position,startSize:r.size,startPos:e},!0):!1}move(e){let t=this.computeSize(e);t&&this.onResize?.(t.panelId,t.size)}computeSize(e){let t=this.state;if(!t)return null;let n=0;switch(t.position){case`bottom`:n=t.startPos.y-e.y;break;case`top`:n=e.y-t.startPos.y;break;case`left`:n=e.x-t.startPos.x;break;case`right`:n=t.startPos.x-e.x;break}return{panelId:t.panelId,size:t.startSize+n}}end(){this.state=null}isActive(){return this.state!==null}};function zd(e,t,n){return e.x>=t.x-n&&e.x<=t.x+t.width+n&&e.y>=t.y-n&&e.y<=t.y+t.height+n}var Bd=10,Vd=6,Hd=16,Ud=18,Wd=8,Gd=16,Kd=15,qd={min:0,max:1,step:.2,ticks:[0,.2,.4,.6,.8,1]};function Jd(e){for(let t=0;t<=Kd;t++){let n=e*10**t,r=Math.round(n);if(r!==0&&Math.abs(r-n)<1e-9*Math.abs(n))return t}return Kd}var Yd=(e,t)=>{let n=Number(e.toFixed(t));return n===0?0:n};function Xd(e,t,n=5){let r=Math.min(e,t),i=Math.max(e,t);if((!Number.isFinite(r)||!Number.isFinite(i))&&(r=0,i=1),r===i){let e=Math.abs(r)||1;r-=e/2,i+=e/2}let a=(i/2-r/2)/Math.max(1,n)*2;if(!Number.isFinite(a)||a<=0)return qd;let o=10**Math.floor(Math.log10(a)),s=a/o,c=(s<=1?1:s<=2?2:s<=2.5?2.5:s<=5?5:10)*o;if(!Number.isFinite(c)||c<=0)return qd;let l=Jd(c),u=Math.floor(r/c+1e-9),d=Math.ceil(i/c-1e-9),f=[];for(let e=u;e<=d;e++)f.push(Yd(e*c,l));return f.length<2||!f.every(Number.isFinite)?qd:{min:f[0],max:f[f.length-1],step:Yd(c,l),ticks:f}}function G(e,t,n,r,i=!1){let a=e.max===e.min?.5:(t-e.min)/(e.max-e.min);return i?n+r*(1-a):n+r*a}var Zd=new Intl.NumberFormat(void 0,{maximumFractionDigits:2}),Qd=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function $d(e){return Math.abs(e)>=1e4?Qd.format(e):Zd.format(e)}function K(e){let t=Jd(e.step),n=new Intl.NumberFormat(void 0,{minimumFractionDigits:t,maximumFractionDigits:t});if(Math.max(Math.abs(e.min),Math.abs(e.max))>=1e4&&e.step%1e3==0){let t=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:2}),n=e.ticks.map(e=>t.format(e));if(new Set(n).size===n.length)return e=>t.format(e)}return e=>n.format(e)}function ef(e,n){return n??t.TC_SERIES_COLORS[e%t.TC_SERIES_COLORS.length]}function q(e,t,n=``){return`${n?`${n} `:``}${t}px ${e.font.family}`}function tf(e,t){return(n,r=11)=>(e.font=q(t,r),e.measureText(n).width)}function nf(e,t,n,r=!1){let i=[],a=0,o=0;for(let s of e){let e=Bd+Vd+n(s.label,11);a>0&&(r||a+e>t)&&(o++,a=0),i.push({...s,x:a,y:o*Ud}),a+=e+Hd}let s=e.length===0?0:o+1;return{items:i,rows:s,height:s*Ud}}function rf(e,t,n,r,i){e.save(),e.font=q(i,11),e.textBaseline=`middle`,e.textAlign=`left`;for(let a of t.items){let t=r+a.y+Ud/2;e.fillStyle=a.color,e.fillRect(n+a.x,t-Bd/2,Bd,Bd),e.fillStyle=i.textSecondary,e.fillText(a.label,n+a.x+Bd+Vd,t)}e.restore()}function af(e,n,r,i,a){if(n.length===0)return;e.save();let o=n.some(e=>e.color)?Bd+Vd:0,s=0;for(let t of n)e.font=q(a,11,t.bold?`600`:``),s=Math.max(s,e.measureText(t.text).width);let c=s+o+Wd*2,l=n.length*Gd+Wd*2-4,u=r.x+14,d=r.y+14;u+c>i.x+i.width&&(u=r.x-14-c),d+l>i.y+i.height&&(d=r.y-14-l),u=Math.max(i.x,u),d=Math.max(i.y,d),e.fillStyle=(0,t.withAlpha)(a.axisLabelBackground,.94),e.strokeStyle=a.grid,e.lineWidth=1,e.beginPath(),typeof e.roundRect==`function`?e.roundRect(u,d,c,l,6):e.rect(u,d,c,l),e.fill(),e.stroke(),e.textBaseline=`middle`,e.textAlign=`left`,n.forEach((t,n)=>{let r=d+Wd+n*Gd+Gd/2-2;t.color&&(e.fillStyle=t.color,e.fillRect(u+Wd,r-4,8,8)),e.font=q(a,11,t.bold?`600`:``),e.fillStyle=t.bold?a.text:a.textSecondary,e.fillText(t.text,u+Wd+o,r)}),e.restore()}function of(e,t,n,r,i,a){e.save(),e.font=q(i,11),e.fillStyle=i.axisLabel,e.strokeStyle=i.grid,e.lineWidth=1;for(let i of n.ticks)if(r===`vertical`){let r=Math.round(G(n,i,t.y,t.height,!0))+.5;e.beginPath(),e.moveTo(t.x,r),e.lineTo(t.x+t.width,r),e.stroke(),e.textAlign=`right`,e.textBaseline=`middle`,e.fillText(a(i),t.x-6,r)}else{let r=Math.round(G(n,i,t.x,t.width))+.5;e.beginPath(),e.moveTo(r,t.y),e.lineTo(r,t.y+t.height),e.stroke(),e.textAlign=`center`,e.textBaseline=`top`,e.fillText(a(i),r,t.y+t.height+6)}e.restore()}function sf(e,t,n,r=11){if(n(e,r)<=t)return e;let i=e;for(;i.length>1&&n(`${i}…`,r)>t;)i=i.slice(0,-1);return i.length>1?`${i}…`:``}var cf=8,lf=32,uf=new Map;function df(e){let t=uf.get(e);return t===void 0&&(t=ff(e),uf.size>512&&uf.clear(),uf.set(e,t)),t}function ff(e){let t=e.trim(),n=t.match(/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i);if(n){let e=n[1];return e.length<=4&&(e=[...e.slice(0,3)].map(e=>e+e).join(``)),[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}let r=t.match(/^rgba?\(\s*(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)/i);return r?[Number(r[1]),Number(r[2]),Number(r[3])]:null}function pf(e,t,n){let r=df(e),i=df(t);if(!r||!i)return n<.5?e:t;let a=e=>Math.round(r[e]+(i[e]-r[e])*n);return`rgb(${a(0)},${a(1)},${a(2)})`}function mf(e,t,n){let r=1/0,i=-1/0;for(let t of e)Number.isFinite(t)&&(t<r&&(r=t),t>i&&(i=t));let a=0,o=1;if(r<=i){let e=Math.max(Math.abs(r),Math.abs(i))||1;a=r<0?-e:0,o=r<0?e:i||1}return{negative:n?.negative??t.candleDown,zero:n?.zero??pf(t.background,t.text,.14),positive:n?.positive??t.candleUp,min:n?.min!==void 0&&Number.isFinite(n.min)?n.min:a,max:n?.max!==void 0&&Number.isFinite(n.max)?n.max:o}}function hf(e,t){return!Number.isFinite(e)||e===0?pf(t.zero,t.zero,0):e<0?pf(t.zero,t.negative,t.min<0?Math.min(1,e/t.min):1):pf(t.zero,t.positive,t.max>0?Math.min(1,e/t.max):1)}var gf=`#11151b`,_f=.0076;function vf(e){let t=df(e);if(!t)return`#ffffff`;let[n,r,i]=t.map(e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}),a=.2126*n+.7152*r+.0722*i;return(a+.05)/(_f+.05)>1.05/(a+.05)?gf:`#ffffff`}function yf(e,t,n,r,i){let a=Math.min(180,t.width);if(a<40||!(n.max>n.min))return;let{x:o,y:s}=t,c=n.max-n.min;e.save();for(let t=0;t<lf;t++){let r=(t+.5)/lf;e.fillStyle=hf(n.min+c*r,n),e.fillRect(o+a*t/lf,s,a/lf+.5,cf)}e.font=q(i,10),e.fillStyle=i.textSecondary,e.textBaseline=`top`;let l=s+cf+4;e.textAlign=`left`,e.fillText(r(n.min),o,l),e.textAlign=`right`,e.fillText(r(n.max),o+a,l);let u=o+a*-n.min/c;n.min<0&&n.max>0&&u-o>28&&o+a-u>28&&(e.textAlign=`center`,e.fillText(r(0),u,l)),e.restore()}var bf=.2,xf=class{position=null;callback=null;data=[];source=null;tz=null;exchangeZone=null;timeFormatter=null;timesPastData=!0;setTimesPastData(e){this.timesPastData=e}getTimesPastData(){return this.timesPastData}setTimeFormatter(e){this.timeFormatter=e}setTimezoneOffset(e){this.tz=e}setExchangeTimeZone(e){this.exchangeZone=e}magnetMode=!0;mode=`magnet`;cursor=`cross`;spanTints=[];pricePrecision=null;locale=`en-US`;syncedSlot=null;pendingBarIndex=null;pendingPoint=null;callbackScheduled=!1;lastCallbackBarIndex=-1;reportTop=null;reportBottom=null;setCallback(e){this.callback=e}setData(e){this.data=e}setDataSource(e){this.source=e}series(){return this.source?.()??this.data}setMagnetMode(e){this.magnetMode=e,this.mode=e?`magnet`:`normal`}setMode(e){this.mode=e,this.magnetMode=e===`magnet`}getMode(){return this.mode}setCursor(e){this.cursor=e}getCursor(){return this.cursor}drawsLines(){return this.mode!==`hidden`&&this.cursor!==`arrow`}setPricePrecision(e){this.pricePrecision=e}setLocale(e){this.locale=e}getPosition(){return this.position}setSyncedSlot(e){this.syncedSlot=e!==null&&Number.isFinite(e)?e:null}getSyncedSlot(){return this.syncedSlot}setReportBounds(e){this.reportTop=e?.top??null,this.reportBottom=e?.bottom??null}onPointerMove(e){this.position=e}getReportedBarIndex(){return this.lastCallbackBarIndex>=0?this.lastCallbackBarIndex:null}refresh(){this.lastCallbackBarIndex<0||!this.pendingPoint||(this.pendingBarIndex=this.lastCallbackBarIndex,this.scheduleCallback())}onPointerLeave(){this.position=null,this.pendingBarIndex=null,this.pendingPoint=null,this.lastCallbackBarIndex=-1,this.flushCallback(null,null)}render(n,r,i){if(this.mode===`hidden`)return;let a=this.cursor!==`arrow`;if(!this.position){this.syncedSlot!==null&&a&&this.renderSynced(n,r,i,this.syncedSlot);return}let{chartRect:o}=r,{x:s,y:c}=this.position;if(s<o.x||s>o.x+o.width)return;let l=o.y+o.height;if(c<Math.min(this.reportTop??o.y,o.y)||c>Math.max(this.reportBottom??l,l))return;let u=c>=o.y&&c<=l,d=e.A(s,r),f=this.series().length,p=Math.max(0,Math.min(f-1,d)),m=d>=0&&d<f;if(this.magnetMode&&(s=e.b(d,r)),p!==this.lastCallbackBarIndex&&(this.pendingBarIndex=p,this.pendingPoint={x:s,y:c},this.lastCallbackBarIndex=p,this.scheduleCallback()),!u||!a)return;let h=ce(i);this.magnetMode&&m&&Cf(n,s,r,h.vertical.color),wf(n,s,o,h.vertical);let g=h.horizontal;if(g.visible){n.setLineDash((0,t.lineDash)(g.style,Sf,g.width)),n.strokeStyle=g.color;let r=e._(n,c,g.width);n.lineWidth=r.width,n.beginPath(),n.moveTo(o.x,r.y),n.lineTo(o.x+o.width,r.y),n.stroke()}n.setLineDash([])}renderAxisLabels(n,r,i,a,o,s=[],c=[]){if(this.mode===`hidden`)return;if(!this.position){this.syncedSlot!==null&&this.renderSyncedTimeLabel(n,r,i,a,this.syncedSlot,o,c);return}let{chartRect:u}=r,{x:d,y:f}=this.position;if(d<u.x||d>u.x+u.width||f<u.y||f>u.y+u.height)return;let p=e.A(d,r);this.magnetMode&&(d=e.b(p,r));let m=`600 ${i.font.sizeSmall}px ${i.font.family}`,h=l(e.M(f,r),r,this.pricePrecision??(0,t.autoPricePrecision)(r.priceRange.min,r.priceRange.max),this.locale),g=u.x+u.width;Of(n,s,f,g,r.priceAxisWidth??t.PRICE_AXIS_WIDTH,i,this.spanTints),kf(n,{text:h,anchorX:g,anchorY:f,orientation:`right`,bg:ce(i).labelBackground,fg:ce(i).labelText,theme:i,font:m}),this.drawTimePill(n,r,i,a,p,d,o,c)}beginSpans(){this.spanTints=[]}renderSpan(e,n,r,i,a,o){let s=`600 ${i.font.sizeSmall}px ${i.font.family}`,c=(0,t.withAlpha)(n.color,bf),l=vf(n.color);n.prices.length>0&&this.renderPriceSpan(e,n,i,s,c,l,r),n.times.length>0&&this.renderTimeSpan(e,n,r,i,a,s,c,l,o)}renderPriceSpan(n,r,i,a,o,s,c){let u=r.viewport,d=u.chartRect,f=d.x+d.width,p=u.priceAxisWidth??t.PRICE_AXIS_WIDTH,m=r.prices.map(t=>e.T(t,u)),h=u===c?this.pricePrecision??(0,t.autoPricePrecision)(u.priceRange.min,u.priceRange.max):b(x(u.priceRange.min,u.priceRange.max,d.height));n.save(),n.beginPath(),n.rect(f,d.y,p,d.height),n.clip(),m.length>1&&(n.fillStyle=o,n.fillRect(f,Math.min(...m),p,Math.abs(m[m.length-1]-m[0])),u===c&&this.spanTints.push({axis:`price`,from:Math.min(...m),to:Math.max(...m),tint:o})),r.prices.forEach((e,t)=>{let o=m[t];o<d.y||o>d.y+d.height||kf(n,{text:l(e,u,h,this.locale),anchorX:f,anchorY:o,orientation:`right`,bg:r.color,fg:s,theme:i,font:a})}),n.restore()}renderTimeSpan(n,r,i,a,o,s,c,l,u){let d=i.chartRect,f=u??d.y+d.height,p=r.times.map(t=>e.O(t,i));n.save(),n.beginPath(),n.rect(d.x,f,d.width,t.TIME_AXIS_HEIGHT),n.clip(),p.length>1&&(n.fillStyle=c,n.fillRect(Math.min(...p),f,Math.abs(p[p.length-1]-p[0]),t.TIME_AXIS_HEIGHT),this.spanTints.push({axis:`time`,from:Math.min(...p),to:Math.max(...p),tint:c})),r.times.forEach((e,t)=>{let i=p[t];i<d.x||i>d.x+d.width||kf(n,{text:this.formatTime(e,o),anchorX:i,anchorY:f,orientation:`bottom`,bg:r.color,fg:l,theme:a,font:s})}),n.restore()}renderSynced(t,n,r,i){let a=e.b(i,n),{chartRect:o}=n;if(a<o.x||a>o.x+o.width)return;let s=ce(r);this.magnetMode&&i>=0&&i<this.series().length&&Cf(t,a,n,s.vertical.color),wf(t,a,o,s.vertical)}renderSyncedTimeLabel(t,n,r,i,a,o,s=[]){let c=e.b(a,n),{chartRect:l}=n;c<l.x||c>l.x+l.width||this.drawTimePill(t,n,r,i,a,c,o,s)}formatTime(e,t){return this.timeText(e,ai(t))}timeText(e,n){return this.timeFormatter?this.timeFormatter(e*(0,t.barTimeUnit)(n),{kind:`crosshair`,timeZone:this.tz}):Af(e*(0,t.barTimeUnit)(n),this.tz,(0,t.barsAreDaily)(n),this.exchangeZone)}drawTimePill(t,n,r,i,a,o,s,c=[]){if(i.length===0||!this.timesPastData&&(a<0||a>=i.length))return;let l=ai(i),u=e.y(a,l),d=this.timeText(u,l),f=`600 ${r.font.sizeSmall}px ${r.font.family}`,p=s??n.chartRect.y+n.chartRect.height;t.font=f;let m=Math.ceil(t.measureText(d).width)/2+Ef;Df(t,c,o-m,o+m,p,r,this.spanTints),kf(t,{text:d,anchorX:o,anchorY:p,orientation:`bottom`,bg:ce(r).labelBackground,fg:ce(r).labelText,theme:r,font:f})}scheduleCallback(){this.callbackScheduled||(this.callbackScheduled=!0,queueMicrotask(()=>{this.callbackScheduled=!1,this.flushCallback(this.pendingBarIndex,this.pendingPoint)}))}flushCallback(e,t){this.callback?.(e,t)}},Sf=[4,4];function Cf(e,t,n,r){let i=n.barWidth+n.barSpacing;e.fillStyle=r,e.globalAlpha=.08,e.fillRect(t-i/2,n.chartRect.y,i,n.chartRect.height),e.globalAlpha=1}function wf(n,r,i,a){if(!a.visible)return;n.setLineDash((0,t.lineDash)(a.style,Sf,a.width)),n.strokeStyle=a.color;let o=e.g(n,r,a.width);n.lineWidth=o.width,n.beginPath(),n.moveTo(o.x,i.y),n.lineTo(o.x,i.y+i.height),n.stroke(),n.setLineDash([])}var Tf=20,Ef=8;function Df(e,t,n,r,i,a,o=[]){let s=t.filter(e=>e.right>n-2&&e.left<r+2);if(s.length===0)return;e.save();let c=a.font.sizeSmall+12;for(let t of s){let n=t.left-2,r=t.right-t.left+4;e.fillStyle=a.background,e.fillRect(n,i+1,r,c);for(let t of o){if(t.axis!==`time`)continue;let a=Math.max(n,t.from),o=Math.min(n+r,t.to);o<=a||(e.fillStyle=t.tint,e.fillRect(a,i+1,o-a,c))}}e.restore()}function Of(e,t,n,r,i,a,o=[]){let s=Math.ceil(a.font.sizeSmall/2)+1,c=t.filter(e=>Math.abs(e-n)<Tf/2+s);if(c.length!==0){e.save();for(let t of c){e.fillStyle=a.background,e.fillRect(r+1,t-s,i-1,s*2);for(let n of o){if(n.axis!==`price`)continue;let a=Math.max(t-s,n.from),o=Math.min(t+s,n.to);o<=a||(e.fillStyle=n.tint,e.fillRect(r+1,a,i-1,o-a))}}e.restore()}}function kf(e,t){e.save(),e.font=t.font;let n=Ef,r=Math.ceil(e.measureText(t.text).width)+n*2,i=Tf;if(e.fillStyle=t.bg,e.textBaseline=`middle`,t.orientation===`right`){let a=t.anchorX+5;O(e,a,t.anchorY-i/2,r,i,t.theme),e.beginPath(),e.moveTo(t.anchorX,t.anchorY),e.lineTo(a+2,t.anchorY-5),e.lineTo(a+2,t.anchorY+5),e.closePath(),e.fill(),e.fillStyle=t.fg,e.textAlign=`left`,e.fillText(t.text,a+n,t.anchorY)}else{let n=t.anchorX-r/2,a=t.anchorY+5;O(e,n,a,r,i,t.theme),e.beginPath(),e.moveTo(t.anchorX,t.anchorY),e.lineTo(t.anchorX-5,a+1),e.lineTo(t.anchorX+5,a+1),e.closePath(),e.fill(),e.fillStyle=t.fg,e.textAlign=`center`,e.fillText(t.text,t.anchorX,a+i/2)}e.restore()}function Af(e,n,r,i){if(r){let r=(0,t.barDateParts)(e,n,i);return`${r.month}/${r.day}/${r.year}`}let a=(0,t.timeParts)(e,n),{year:o,month:s,day:c,hours:l,minutes:u}=a;return r===void 0&&(0,t.isDateOnly)(a)?`${s}/${c}/${o}`:`${s}/${c} ${l<10?`0`+l:l}:${u<10?`0`+u:u}`}var jf=[`cross`,`dot`,`arrow`];function Mf(e){return typeof e==`string`&&jf.includes(e)}var Nf=9,Pf=3,Ff=1.5;function If(e){return e.replace(/['"<>&]/g,``)}function Lf(e,t,n){if(e===`arrow`)return`default`;if(e===`cross`)return`crosshair`;let r=Nf/2,i=`<svg xmlns='http://www.w3.org/2000/svg' width='${Nf}' height='${Nf}'><circle cx='${r}' cy='${r}' r='${Pf}' fill='${If(t)}' stroke='${If(n)}' stroke-width='${Ff}'/></svg>`,a=Math.floor(r);return`url("data:image/svg+xml,${encodeURIComponent(i)}") ${a} ${a}, crosshair`}var Rf=class{callbacks;enabled=!0;constructor(e){this.callbacks=e}setEnabled(e){this.enabled=e}handleKey(e){if(!this.enabled)return!1;let t=e.shiftKey?10:1;switch(e.key){case`ArrowLeft`:return this.callbacks.scrollBars(-t),!0;case`ArrowRight`:return this.callbacks.scrollBars(t),!0;case`ArrowUp`:case`+`:case`=`:return this.callbacks.zoom(.1),!0;case`ArrowDown`:case`-`:return this.callbacks.zoom(-.1),!0;case`Home`:return this.callbacks.goToStart(),!0;case`End`:return this.callbacks.goToEnd(),!0;case` `:return this.callbacks.fitContent(),!0;default:return!1}}},zf=16,Bf=80,Vf=864e5,Hf={month:`short`,day:`numeric`},Uf={month:`short`,day:`numeric`,year:`numeric`};function Wf(e,n,r,i){return(0,t.zonedDateFormatter)(r,i?Uf:Hf,n)(e)}var Gf=e=>e<10?`0${e}`:`${e}`;function Kf(e,n,r,i=`en-US`,a,o){let s=(0,t.normalizeBarTime)(e,a),c=(0,t.timeParts)(s,n);if(r!==void 0&&r>0?r>=Vf:(0,t.isDateOnly)(c))return Wf(s,(0,t.barDateZone)(s,n,o),i,!0);let l=Wf(s,n,i,!1),u=`${Gf(c.hours)}:${Gf(c.minutes)}`;return r!==void 0&&r>0&&r<6e4?`${l} · ${u}:${Gf(new Date(s).getUTCSeconds())}`:`${l} · ${u}`}var qf=1e4;function Jf(e,n){return Number.isFinite(e)?(0,t.usesKoreanUnits)(n)&&e>=qf?(0,t.formatVolumeLoc)(e,n):(0,t.usesKoreanUnits)(n)?(0,t.formatPrice)(e,e%1==0?0:2,n):e>=1e9?`${(0,t.formatPrice)(e/1e9,2,n)}B`:e>=1e6?`${(0,t.formatPrice)(e/1e6,2,n)}M`:e>=1e3?`${(0,t.formatPrice)(e/1e3,1,n)}K`:(0,t.formatPrice)(e,e%1==0?0:2,n):`—`}var Yf=class{el=null;visible=!1;appliedTheme=null;locale=`en-US`;pricePrecision=null;tz=null;exchangeZone=null;priceFormatter=null;timeFormatter=null;dirEl;timeEl;changeEl;valueEls;labelEls=[];dividerEl;width=176;height=112;create(e){if(this.el)return;let t=document.createElement(`div`);t.setAttribute(`aria-hidden`,`true`),Object.assign(t.style,{position:`absolute`,left:`0`,top:`0`,display:`none`,minWidth:`168px`,padding:`8px 10px 9px`,borderRadius:`var(--tcw-tooltip-radius, 8px)`,fontSize:`11.5px`,lineHeight:`1.45`,fontVariantNumeric:`tabular-nums`,pointerEvents:`none`,zIndex:`100`,whiteSpace:`nowrap`,willChange:`transform`,contain:`layout paint`,backdropFilter:`blur(10px)`}),n(t);let r=Xf({display:`flex`,alignItems:`center`,gap:`7px`,marginBottom:`6px`});this.dirEl=Xf({width:`3px`,height:`12px`,borderRadius:`2px`,flex:`none`}),this.timeEl=Xf({flex:`1`,fontSize:`11px`,letterSpacing:`0.01em`}),this.changeEl=Xf({padding:`1px 6px`,borderRadius:`999px`,fontSize:`10.5px`,fontWeight:`600`}),r.append(this.dirEl,this.timeEl,this.changeEl);let i=Xf({display:`grid`,gridTemplateColumns:`auto 1fr auto 1fr`,columnGap:`8px`,rowGap:`1px`,alignItems:`baseline`}),a=e=>{let t=Xf({fontSize:`10px`,letterSpacing:`0.04em`});t.textContent=e,this.labelEls.push(t);let n=Xf({textAlign:`right`,fontWeight:`500`});return i.append(t,n),n},o=a(`O`),s=a(`H`),c=a(`L`),l=a(`C`);this.dividerEl=Xf({height:`1px`,margin:`6px 0 5px`});let u=Xf({display:`flex`,justifyContent:`space-between`,gap:`12px`}),d=Xf({fontSize:`10px`,letterSpacing:`0.04em`});d.textContent=`VOL`,this.labelEls.push(d);let f=Xf({fontWeight:`500`});u.append(d,f),this.valueEls={open:o,high:s,low:c,close:l,volume:f},t.append(r,i,this.dividerEl,u),e.appendChild(t),this.el=t}setLocale(e){this.locale=e}setPricePrecision(e){this.pricePrecision=e}setTimezoneOffset(e){this.tz=e}setExchangeTimeZone(e){this.exchangeZone=e}setPriceFormatter(e){this.priceFormatter=e}setTimeFormatter(e){this.timeFormatter=e}show(e,n,r,i,a={}){let o=this.el;if(!o)return;this.appliedTheme!==r&&this.applyTheme(r);let s=this.pricePrecision??(a.priceRange?(0,t.autoPricePrecision)(a.priceRange.min,a.priceRange.max):(0,t.autoPricePrecision)(n.low,n.high)),c=e=>this.priceFormatter?.(e)??(0,t.formatPrice)(e,s,this.locale),l=a.prevClose??n.open,u=n.close-l,d=l===0?0:u/l*100,f=u>=0,p=f?r.candleUp:r.candleDown,m=f?`+`:`−`;this.timeEl.textContent=this.timeFormatter?this.timeFormatter((0,t.normalizeBarTime)(n.time,a.timeUnit),{kind:`crosshair`,timeZone:this.tz}):Kf(n.time,this.tz,a.barStepMs,this.locale,a.timeUnit,this.exchangeZone),this.changeEl.textContent=`${m}${(0,t.formatPrice)(Math.abs(d),2,this.locale)}%`,this.changeEl.style.color=p,this.changeEl.style.background=$f(p,.14),this.dirEl.style.background=n.close>=n.open?r.candleUp:r.candleDown,this.valueEls.open.textContent=c(n.open),this.valueEls.high.textContent=c(n.high),this.valueEls.low.textContent=c(n.low),this.valueEls.close.textContent=c(n.close),this.valueEls.close.style.color=n.close>=n.open?r.candleUp:r.candleDown,this.valueEls.volume.textContent=Jf(n.volume,this.locale),this.visible||=(o.style.display=`block`,!0),this.width=o.offsetWidth||this.width,this.height=o.offsetHeight||this.height;let h=a.plot??{x:0,y:0,width:i.width-Bf,height:i.height},g=h.x+h.width,_=h.y+h.height,v=e.x+zf,y=e.y-this.height/2;v+this.width>g-4&&(v=e.x-this.width-zf),v<h.x+4&&(v=h.x+4),y+this.height>_-4&&(y=_-this.height-4),y<h.y+4&&(y=h.y+4),o.style.transform=`translate(${Math.round(v)}px, ${Math.round(y)}px)`}hide(){this.el&&this.visible&&(this.el.style.display=`none`,this.visible=!1)}isVisible(){return this.visible}destroy(){this.el?.remove(),this.el=null,this.visible=!1,this.appliedTheme=null,this.labelEls=[]}applyTheme(e){let t=this.el,n=Zf(e.background);t.style.background=$f(e.background,n?.9:.94),t.style.border=`1px solid ${e.axisLine}`,t.style.boxShadow=n?`0 12px 32px -8px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.35)`:`0 12px 32px -10px rgba(15, 19, 26, 0.22), 0 2px 6px rgba(15, 19, 26, 0.08)`,t.style.color=e.text,t.style.fontFamily=e.font.family,this.timeEl.style.color=e.textSecondary;for(let t of this.labelEls)t.style.color=e.textSecondary;this.dividerEl.style.background=e.axisLine,this.appliedTheme=e}};function Xf(e){let t=document.createElement(`div`);return Object.assign(t.style,e),t}function Zf(e){let t=Qf(e);return t?(.299*t[0]+.587*t[1]+.114*t[2])/255<.5:!0}function Qf(e){if(e.startsWith(`#`)){let t=e.slice(1),n=t.length===3?t.split(``).map(e=>e+e).join(``):t.slice(0,6);return[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)]}let t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);return t?[Number(t[1]),Number(t[2]),Number(t[3])]:null}function $f(e,t){let n=Qf(e);return n?`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${t})`:`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}var ep=2,tp=2,np=`0.7`,rp=class{el=null;deltaEl=null;timeEl=null;ohlcEl=null;pinnedBar=null;pinnedIndex=-1;tz=null;exchangeZone=null;priceFormatter=null;pricePrecision=null;locale=`en-US`;setTimezone(e){this.tz=e}setExchangeTimeZone(e){this.exchangeZone=e}setPriceFormatter(e){this.priceFormatter=e}setPricePrecision(e){this.pricePrecision=e!==null&&Number.isInteger(e)&&e>=0?e:null}setLocale(e){this.locale=e}fmt(e){return this.priceFormatter?this.priceFormatter(e):(0,t.formatPrice)(e,this.pricePrecision??ep,this.locale)}create(e){if(this.el)return;this.el=document.createElement(`div`),Object.assign(this.el.style,{position:`absolute`,display:`none`,padding:`6px 10px`,borderRadius:`var(--tcw-tooltip-radius, 4px)`,fontSize:`11px`,fontFamily:`-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif`,lineHeight:`1.5`,pointerEvents:`auto`,cursor:`pointer`,zIndex:`99`,whiteSpace:`nowrap`,willChange:`transform`}),n(this.el),this.timeEl=document.createElement(`div`),this.ohlcEl=document.createElement(`div`),this.deltaEl=document.createElement(`div`),this.deltaEl.style.marginTop=`4px`,this.deltaEl.style.paddingTop=`4px`,this.deltaEl.style.borderTop=`1px solid currentColor`,this.deltaEl.style.opacity=`0.85`,this.deltaEl.style.fontVariantNumeric=`tabular-nums`,this.el.appendChild(this.timeEl),this.el.appendChild(this.ohlcEl),this.el.appendChild(this.deltaEl);let r=document.createElement(`div`);r.innerHTML=`${(0,t.iconSvg)(t.UI_ICONS.pin,10)}<span>pinned</span>`,r.style.display=`flex`,r.style.alignItems=`center`,r.style.gap=`3px`,r.style.fontSize=`9px`,r.style.opacity=`0.6`,r.style.marginBottom=`2px`,r.style.letterSpacing=`0.04em`,r.style.textTransform=`uppercase`,this.el.insertBefore(r,this.timeEl),e.appendChild(this.el)}pin(e,n,r,i,a=!1){if(!this.el||!this.timeEl||!this.ohlcEl)return;this.pinnedBar=e,this.pinnedIndex=n;let o=e.close>=e.open?r.candleUp:r.candleDown,s=(0,t.normalizeBarTime)(e.time,i),c=a?(0,t.barDateParts)(s,this.tz,this.exchangeZone):(0,t.timeParts)(s,this.tz);this.timeEl.textContent=a?`${c.month}/${c.day}/${c.year}`:`${c.month}/${c.day} ${ip(c.hours)}:${ip(c.minutes)}`,this.timeEl.style.color=r.textSecondary;let l=[];for(let[t,n]of[[`O `,e.open],[` H `,e.high],[` L `,e.low],[` C `,e.close]]){let e=document.createElement(`span`);e.style.opacity=`.6`,e.textContent=t;let r=document.createElement(`span`);r.style.color=o,r.textContent=this.fmt(n),l.push(e,r)}this.ohlcEl.replaceChildren(...l);let u=ap(r.background);this.el.style.background=op(r.background,u?.96:.97),this.el.style.border=`1px solid ${o}`,this.el.style.boxShadow=u?`0 4px 12px rgba(0,0,0,0.55)`:`0 4px 12px rgba(0,0,0,0.18)`,this.el.style.color=r.text,this.el.style.backdropFilter=`blur(8px)`,this.el.style.display=`block`}unpin(){this.pinnedBar=null,this.pinnedIndex=-1,this.el&&(this.el.style.display=`none`)}isPinned(){return this.pinnedBar!==null}getPinnedIndex(){return this.pinnedIndex}reposition(n,r,i,a){if(!this.el||!this.pinnedBar)return;let o=e.b(this.pinnedIndex,n),s=e.T(this.pinnedBar.close,n),c=n.chartRect,l=o>=c.x-4&&o<=c.x+c.width+4;this.el.style.opacity=l?`1`:`0.35`;let u=Math.max(c.x,Math.min(c.x+c.width-180,o+8)),d=Math.max(c.y,Math.min(c.y+c.height-90,s-64));if(this.el.style.transform=`translate(${Math.round(u)}px, ${Math.round(d)}px)`,this.el.style.left=`0`,this.el.style.top=`0`,this.deltaEl)if(r&&i!==null&&i!==this.pinnedIndex){let e=r.close-this.pinnedBar.close,n=this.pinnedBar.close===0?0:e/this.pinnedBar.close*100,o=e>0?`+`:e<0?`−`:``,s=i-this.pinnedIndex,c=e>=0?a.candleUp:a.candleDown;this.deltaEl.style.color=c;let l=(0,t.formatPrice)(Math.abs(n),tp,this.locale),u=document.createElement(`span`);u.style.opacity=np,u.textContent=`(${o}${l}%)`,this.deltaEl.replaceChildren(`Δ ${o}${this.fmt(Math.abs(e))} `,u,` · ${s>0?`+`:``}${s} bars`),this.deltaEl.style.display=`block`}else this.deltaEl.style.display=`none`}destroy(){this.el?.remove(),this.el=null,this.deltaEl=null,this.timeEl=null,this.ohlcEl=null,this.pinnedBar=null,this.pinnedIndex=-1}};function ip(e){return e<10?`0`+e:``+e}function ap(e){if(e.startsWith(`#`)){let t=e.slice(1),n=t.length===3?t.split(``).map(e=>e+e).join(``):t.slice(0,6),r=parseInt(n.slice(0,2),16),i=parseInt(n.slice(2,4),16),a=parseInt(n.slice(4,6),16);return(.299*r+.587*i+.114*a)/255<.5}return!0}function op(e,t){if(e.startsWith(`#`)){let n=e.slice(1),r=n.length===3?n.split(``).map(e=>e+e).join(``):n.slice(0,6);return`rgba(${parseInt(r.slice(0,2),16)}, ${parseInt(r.slice(2,4),16)}, ${parseInt(r.slice(4,6),16)}, ${t})`}return e}var sp=class{listeners=new Map;tauriBridge=null;on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}hasListeners(e){return(this.listeners.get(e)?.size??0)>0}emit(e,t){let n={type:e,timestamp:Date.now(),payload:t},r=this.listeners.get(e);if(r)for(let e of r)e(n);if(this.tauriBridge?.enabled&&window.__TAURI__){let t=this.tauriBridge.eventPrefix??`tc-chart`;window.__TAURI__.event.emit(`${t}:${e}`,n).catch(()=>{})}}enableTauriBridge(e){this.tauriBridge=e}disableTauriBridge(){this.tauriBridge=null}destroy(){this.listeners.clear(),this.tauriBridge=null}},cp=1.5,lp=1.5,up=1,dp=2.5,fp=.7,pp=4,mp=.2,hp={primary:null,hover:null,drag:null};function gp(e){hp=e??{primary:null,hover:null,drag:null}}function _p(e,t,n){return(Math.round(e*t+n-.5)+.5-n)/t}function vp(e,t,n,r){e.beginPath(),e.arc(t,n,r,0,Math.PI*2)}function yp(e,n,r,i={}){let a=M(),o=n.style.color,s=e.getTransform?.()??{a:1,d:1,e:0,f:0},c=n.id===hp.primary&&!n.locked;e.save(),e.setLineDash([]),r.forEach((r,l)=>{let u=_p(r.x,s.a||1,s.e??0),d=_p(r.y,s.d||1,s.f??0),f=An(n.style.lineWidth)+lp;if(hn(u-f,d-f,f*2,f*2),!c){vp(e,u,d,dp*a.scale),e.globalAlpha=fp,e.fillStyle=o,e.fill(),e.globalAlpha=1;return}let p=An(n.style.lineWidth)-(i.sides?.has(l)?up:0),m=hp.drag?.id===n.id&&hp.drag.index===l,h=!m&&hp.hover?.id===n.id&&hp.hover.index===l||m?p+lp:p;m&&(vp(e,u,d,h+pp),e.fillStyle=(0,t.withAlpha)(o,mp),e.fill()),vp(e,u,d,h),e.fillStyle=m?o:a.handleFill,e.fill(),e.strokeStyle=m?a.background:o,e.lineWidth=cp,e.stroke()}),e.restore()}function bp(e){return e?.anchoring===`screen`}var xp=24;function Sp(e,t,n){return Math.max(t,Math.min(e,Math.max(t,n)))}function Cp(e,t){let n=t.chartRect;return{x:Sp(n.x+e.time*n.width,n.x,n.x+n.width-xp),y:Sp(n.y+e.price*n.height,n.y+xp,n.y+n.height-xp)}}function wp(e){let t=e=>Number.isFinite(e)?Math.min(1,Math.max(0,e)):0;return e.map(e=>({time:t(e.time),price:t(e.price)}))}function Tp(e,t){let n=t.chartRect,r=(e,t)=>t>0?Math.min(1,Math.max(0,e/t)):0;return{time:r(e.x-n.x,n.width),price:r(e.y-n.y,n.height)}}function Ep(e,t,n,r){return e.map(e=>{let i=Cp(e,r);return Tp({x:i.x+t,y:i.y+n},r)})}function Dp(e,t){let n=e=>Math.min(1,Math.max(0,e+t<=1?e+t:e-t));return e.map(e=>({time:n(e.time),price:n(e.price)}))}var Op={at:e=>e,value:e=>e,price:e=>e};function kp(t){if(!t)return Op;let{min:n,max:r}=t.priceRange,i=t.logScale===!0&&n>0&&r>0;return{at:n=>e.D(n,t),value:i?e=>Math.log(Math.max(e,2**-52)):e=>e,price:i?Math.exp:e=>e}}function Ap(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;if(a===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function jp(e,t,n,r=!1){for(let r=0;r<t.length-1;r++)if(Ap(e,t[r],t[r+1])<=n)return!0;return r&&t.length>2&&Ap(e,t[t.length-1],t[0])<=n}function Mp(e,t){switch(e.kind){case`boolean`:return typeof t==`boolean`;case`number`:return typeof t==`number`&&Number.isFinite(t);case`levels`:return Array.isArray(t);default:return typeof t==`string`}}var Np=.55,J=class{hitTestAnchor(e,t,n,r){let i=-1,a=1/0,o=this.handlePoints(t,n);for(let t=0;t<o.length;t++){let n=o[t],s=Math.hypot(e.x-n.x,e.y-n.y);s<=r&&s<a&&(i=t,a=s)}return i}option(e,t){let n=this.descriptor.options?.[t],r=e.options?.[t];return n?r!==void 0&&Mp(n,r)?r:n.default:r}optionsOf(e){return t=>this.option(e,t)}visibleLevels(e,t=`levels`){return this.option(e,t).filter(e=>e.visible&&Number.isFinite(e.value))}extendLine(e,t,n,r,i){let a=t.x-e.x,o=t.y-e.y,s=Math.hypot(a,o);if(s===0||!r&&!i)return[e,t];let c=Math.hypot(n.chartRect.width,n.chartRect.height)*2,l=a/s*c,u=o/s*c;return[r?{x:e.x-l,y:e.y-u}:e,i?{x:t.x+l,y:t.y+u}:t]}linePriceAt(e,t,n,r,i,a=Op){let o=this.lineValueAt(e,t,n,r,i,a);return o===null?null:a.price(o)}lineValueAt(e,t,n,r,i,a){let o=a.at(e.time),s=a.at(t.time);if(o===s)return null;let c=(a.at(n)-o)/(s-o);if(!Number.isFinite(c)||c<0&&!r||c>1&&!i)return null;let l=a.value(e.price);return l+(a.value(t.price)-l)*c}anchorToPixel(t,n){return bp(this.descriptor)?Cp(t,n):{x:e.O(t.time,n),y:e.T(t.price,n)}}pixelToAnchor(t,n){return bp(this.descriptor)?Tp(t,n):{time:e.j(t.x,n),price:e.M(t.y,n)}}applyLineStyle(e,t){e.strokeStyle=t.color,e.lineWidth=t.lineWidth,e.lineCap=t.lineStyle===`dashed`?`butt`:`round`,e.lineJoin=`round`,e.setLineDash(Pn(t.lineStyle,t.lineWidth))}strokeHorizontal(t,n,r,i){let a=e._(t,i,Number(t.lineWidth)||1);t.lineWidth=a.width,t.beginPath(),t.moveTo(n,a.y),t.lineTo(r,a.y),t.stroke()}strokeVertical(t,n,r,i){let a=e.g(t,n,Number(t.lineWidth)||1);t.lineWidth=a.width,t.beginPath(),t.moveTo(a.x,r),t.lineTo(a.x,i),t.stroke()}resetLineStyle(e){e.setLineDash([]),e.lineCap=`butt`,e.lineJoin=`miter`}handlePoints(e,t){return e.anchors.map(e=>this.anchorToPixel(e,t))}timeHandles(e,t){let n=t.chartRect.y+t.chartRect.height/2;return e.anchors.map(e=>({x:this.anchorToPixel(e,t).x,y:n}))}strokeCrispRect(e,t,n,r,i){let a=Math.min(t,t+r),o=Math.max(t,t+r),s=Math.min(n,n+i),c=Math.max(n,n+i);this.strokeHorizontal(e,a,o,s),this.strokeHorizontal(e,a,o,c),this.strokeVertical(e,a,s,c),this.strokeVertical(e,o,s,c)}applyGuideStyle(e,t,n=!1){e.strokeStyle=t,e.lineWidth=1,e.lineCap=`butt`,e.globalAlpha=Np,e.setLineDash(n?Pn(`guide`,1):[])}renderAnchorHandles(e,t,n){yp(e,t,this.handlePoints(t,n))}distanceToLine(e,t,n){return Ap(e,t,n)}distanceToInfiniteLine(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=Math.hypot(r,i);return a===0?Math.hypot(e.x-t.x,e.y-t.y):Math.abs(r*(t.y-e.y)-i*(t.x-e.x))/a}};function Pp(e){if(typeof e!=`string`)return;let t=e.trim().slice(0,80);return t.length>0?t:void 0}function Fp(e){let t={};for(let[n,r]of Object.entries(e))t[n]=Array.isArray(r)?r.map(e=>({...e})):r;return t}function Y(e){return{...e,anchors:e.anchors.map(e=>({...e})),style:{...e.style},options:e.options?Fp(e.options):void 0,intervals:e.intervals?Na(e.intervals):void 0,group:e.group?{...e.group}:void 0,meta:e.meta?{...e.meta}:void 0}}function Ip(e,t){return JSON.stringify(e??{})===JSON.stringify(t??{})}function Lp(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n].time!==t[n].time||e[n].price!==t[n].price)return!1;return!0}var Rp=1,zp=1,Bp=/^tc_drawing_(\d+)$/,Vp=/^tc_group_(\d+)$/;function Hp(){return`tc_drawing_${Rp++}`}function Up(){let e=zp++;return{id:`tc_group_${e}`,number:e}}function Wp(e){for(let t of e){let e=Bp.exec(t.id);e&&(Rp=Math.max(Rp,Number(e[1])+1));let n=t.group?Vp.exec(t.group.id):null;n&&(zp=Math.max(zp,Number(n[1])+1))}}function Gp(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Set(t);return[...t.map(e=>n.get(e)).filter(e=>e!==void 0),...e.filter(e=>!r.has(e.id))]}function Kp(e,t,n){let r=t-1;if(typeof n==`number`)return Number.isInteger(n)?Math.min(r,Math.max(0,n)):e;switch(n){case`front`:return r;case`back`:return 0;case`forward`:return Math.min(r,e+1);case`backward`:return Math.max(0,e-1)}}function qp(e,t){return e.map(e=>e.id===t.id?structuredClone(t):e)}function Jp(e,t){switch(t.type){case`drawingBatch`:return[...t.actions??[]].reverse().reduce(Jp,[...e]);case`drawingCreate`:return t.after?e.filter(e=>e.id!==t.after.id):[...e];case`drawingRemove`:{if(!t.before)return[...e];let n=[...e];return n.splice(Math.min(t.index??n.length,n.length),0,structuredClone(t.before)),n}case`drawingOrder`:return t.order?Gp(e,t.order.before):[...e];case`drawingModify`:return t.before?qp(e,t.before):[...e];default:return[...e]}}function Yp(e,t){switch(t.type){case`drawingBatch`:return(t.actions??[]).reduce(Yp,[...e]);case`drawingCreate`:return t.after?[...e,structuredClone(t.after)]:[...e];case`drawingRemove`:return t.before?e.filter(e=>e.id!==t.before.id):[...e];case`drawingOrder`:return t.order?Gp(e,t.order.after):[...e];case`drawingModify`:return t.after?qp(e,t.after):[...e];default:return[...e]}}var Xp={"]":[`forward`,`front`],"}":[`front`,`front`],"[":[`backward`,`back`],"{":[`back`,`back`]};function Zp(e,t,n){if(e===`Escape`)return`escape`;if(e===`Enter`&&!t)return`finish`;if(e===`Delete`||e===`Backspace`)return`delete`;if(!t)return null;let r=n??(e.length===1&&e!==e.toLowerCase()),i=Xp[e];if(i)return i[+!!r];switch(e.toLowerCase()){case`c`:return`copy`;case`v`:return`paste`;case`d`:return`duplicate`;case`g`:return r?`ungroup`:`group`;case`z`:return r?`redo`:`undo`;case`y`:return`redo`;default:return null}}var Qp=2,$p=6;function em(e){return e.descriptor.creation??`clicks`}var tm=class{drawing=null;plugin=null;preview=null;lastPos=null;dragging=!1;step=Qp;get current(){return this.drawing}reset(){this.drawing=null,this.plugin=null,this.preview=null,this.lastPos=null,this.dragging=!1,this.step=Qp}press(e,t,n,r,i){if(this.dragging)return`continue`;let a=em(e);if(!this.drawing)return this.plugin=e,this.drawing={...t(),anchors:[n]},this.preview=null,this.lastPos=r,a===`freehand`?(this.dragging=!0,`continue`):a===`clicks`&&e.descriptor.requiredAnchors<=1?`done`:`continue`;let o=this.drawing.anchors[this.drawing.anchors.length-1],s=i?i(o):this.lastPos;if(a===`path`&&s&&Math.hypot(r.x-s.x,r.y-s.y)<=$p)return this.finish();this.commit(n,r);let c=a===`path`?e.descriptor.maxAnchors??100:e.descriptor.requiredAnchors;return this.drawing.anchors.length>=c?`done`:`continue`}move(e,t){if(!this.drawing||!this.plugin)return!1;if(this.dragging){let n=this.lastPos;return n&&Math.hypot(t.x-n.x,t.y-n.y)<this.step?!0:(this.drawing.anchors.length>=2e3&&(this.drawing.anchors=this.drawing.anchors.filter((e,t)=>t%2==0),this.step*=2),this.commit(e,t),!0)}return em(this.plugin)===`path`||this.drawing.anchors.length<this.plugin.descriptor.requiredAnchors?(this.preview=e,!0):!1}release(){return this.dragging?(this.dragging=!1,this.hasEnough()?`done`:`cancel`):null}undoPoint(){return!this.drawing||this.dragging||this.drawing.anchors.length<=1?(this.reset(),!1):(this.drawing.anchors.pop(),this.preview=null,this.lastPos=null,!0)}finish(){return!this.plugin||em(this.plugin)!==`path`||!this.hasEnough()?`continue`:(this.preview=null,`done`)}previewState(){return this.drawing?this.preview?{...this.drawing,anchors:[...this.drawing.anchors,this.preview]}:this.drawing:null}take(){let e=this.drawing;return this.reset(),e}hasEnough(){return!!this.drawing&&!!this.plugin&&this.drawing.anchors.length>=Math.max(2,this.plugin.descriptor.requiredAnchors)}commit(e,t){this.drawing.anchors.push(e),this.preview=null,this.lastPos=t}},nm=50;function rm(e,t,n,r,i){return im(e,t,n,r,e=>[r[e].open,r[e].high,r[e].low,r[e].close],i)}function im(t,n,r,i,a,o){if(r===`none`||i.length===0)return{time:t,price:n};let s=!!(o?.data&&o.data.length>0),c=Math.round(s?e.k(t,i):t);if(c<0||c>i.length-1)return{time:t,price:n};let l=s?i[c].time:c,u=a(c).filter(e=>Number.isFinite(e));if(u.length===0)return{time:l,price:n};let d=u[0];for(let e of u)Math.abs(n-e)<Math.abs(n-d)&&(d=e);return r===`magnet`&&o&&Math.abs(e.T(n,o)-e.T(d,o))>nm?{time:l,price:n}:{time:l,price:d}}var am=class{primaryId=null;others=new Set;listener=null;setListener(e){this.listener=e}change(e){let t=this.ids().join(`\0`),n=e();return this.listener&&this.ids().join(`\0`)!==t&&this.listener(this.ids()),n}get primary(){return this.primaryId}has(e){return e===this.primaryId||this.others.has(e)}ids(){return this.primaryId?[this.primaryId,...this.others]:[]}clear(){this.change(()=>{this.primaryId=null,this.others.clear()})}add(e){this.change(()=>{this.primaryId?e!==this.primaryId&&this.others.add(e):this.primaryId=e})}only(e,t=[]){this.change(()=>{this.primaryId=e,this.others.clear();for(let n of t)n!==e&&this.others.add(n)})}focus(e){e===this.primaryId||!this.others.has(e)||this.change(()=>{this.primaryId&&this.others.add(this.primaryId),this.others.delete(e),this.primaryId=e})}remove(e){return this.change(()=>this.removeNow(e))}removeNow(e){let t=!1;for(let n of e)this.others.delete(n)&&(t=!0),n===this.primaryId&&(this.primaryId=null,t=!0);if(!this.primaryId){let e=this.others.values().next();e.done||(this.primaryId=e.value,this.others.delete(e.value))}return t}},om=Math.PI/4,sm=new Set([`trendLine`,`ray`,`extendedLine`,`infoLine`,`trendAngle`,`arrow`,`horizontalRay`,`measure`,`priceRange`,`dateRange`,`dateAndPriceRange`,`path`,`polyline`,`fibRetracement`,`fibExtension`]);function cm(e){return sm.has(e)}function lm(e,t){let n=t.x-e.x,r=t.y-e.y;if(n===0&&r===0)return t;let i=Math.round(Math.atan2(r,n)/om)*om,a=Math.cos(i),o=Math.sin(i),s=n*a+r*o;return{x:e.x+um(s*a),y:e.y+um(s*o)}}function um(e){return Math.abs(e)<1e-9?0:e}function dm(t,n,r){let i=fm(t,r),a=lm(i,n);if(a.x===i.x)return{time:t.time,price:e.M(a.y,r)};let o=e.j(a.x,r);if(a.y===i.y)return{time:o,price:t.price};let s=e.O(o,r)-i.x;return{time:o,price:e.M(i.y+Math.sign(a.y-i.y)*Math.abs(s),r)}}function fm(t,n){return{x:e.O(t.time,n),y:e.T(t.price,n)}}function pm(e,t,n){let r=-1,i=1/0;return e.forEach((e,a)=>{let o=fm(e,n),s=Math.hypot(o.x-t.x,o.y-t.y);s<i&&(r=a,i=s)}),r}var mm=3,hm=class{start=null;handle=-1;grabbed=[];held=-1;constructor(e,t=()=>!1){this.find=e,this.onScreen=t}isActive(){return this.start!==null}activeHandle(){return this.start===null?-1:this.handle}beginMove(e,t){this.start=e,this.handle=-1,this.held=-1,this.grabbed=t.map(e=>({id:e.id,anchors:e.anchors.map(e=>({...e})),before:Y(e)}))}beginResize(e,t,n){this.start=e,this.handle=n,this.grabbed=[{id:t.id,anchors:t.anchors.map(e=>({...e})),before:Y(t)}]}move(e,t,n,r){return!this.start||this.grabbed.length===0?!1:this.handle>=0?this.reshape(e,t,n,r):this.translate(e,t,r)}end(){let e=this.grabbed.flatMap(({id:e,before:t})=>{let n=this.find(e);return n?[{before:t,drawing:n}]:[]});return this.start=null,this.handle=-1,this.grabbed=[],e}translate(e,t,n){let r=this.start,i=e.x-r.x,a=e.y-r.y;if(Math.hypot(i,a)<mm&&this.unmoved())return!0;let o=t.barWidth+t.barSpacing,s=o>0?Math.round(i/o):0,c=this.find(this.grabbed[0].id),l=n&&c&&!this.onScreen(c)?this.snapHeld(s,a,t,n):null;return l&&(a+=l.dy),this.grabbed.forEach(({id:n,anchors:o},c)=>{let u=this.find(n);if(!(!u||u.locked)){if(this.onScreen(u)){u.anchors=Ep(o,i,e.y-r.y,t);return}u.anchors=gm(o,s,a,t),c===0&&l&&(u.anchors[this.held]={...u.anchors[this.held],price:l.price})}}),!0}snapHeld(t,n,r,i){let a=this.grabbed[0];this.held<0&&(this.held=pm(a.anchors,this.start,r));let o=a.anchors[this.held];if(!o)return null;let[s]=gm([o],t,n,r),{price:c}=i.snap(s);return c===s.price?null:{price:c,dy:e.T(c,r)-e.T(s.price,r)}}unmoved(){return this.grabbed.every(({id:e,anchors:t})=>{let n=this.find(e)?.anchors;return!n||n.every((e,n)=>e.time===t[n]?.time&&e.price===t[n]?.price)})}reshape(n,r,i,a){let o=this.find(this.grabbed[0].id);if(!o)return!1;let s=this.onScreen(o)?Tp(n,r):a?a.handleAt(n,o,this.handle):{time:e.j(n.x,r),price:e.M(n.y,r)};if(i?.moveHandle){let e=i.moveHandle(Y(o),this.handle,s);o.anchors=e.anchors,o.options=e.options&&Object.keys(e.options).length>0?(0,t.sanitizeDrawingOptions)(i.descriptor.options,e.options):void 0}else this.handle<o.anchors.length&&(o.anchors[this.handle]=s);return!0}};function gm(t,n,r,i){let a=i.data,o=t=>{let r=e.D(t,i)+n;return a&&a.length>0?e.y(r,a):r};return t.map(t=>({time:n===0?t.time:o(t.time),price:r===0?t.price:e.M(e.T(t.price,i)+r,i)}))}function _m(e){let t=e.filter(Number.isFinite);if(t.length===0)return[];let n=Math.min(...t),r=Math.max(...t);return n===r?[n]:[n,r]}function vm(e,t){let n=t.axisSpan??`both`;if(n===`none`||t.anchoring===`screen`)return null;let r=n===`time`?[]:_m(e.anchors.map(e=>e.price)),i=n===`price`?[]:_m(e.anchors.map(e=>e.time));return r.length===0&&i.length===0?null:{prices:r,times:i}}var ym={drawings:[],pastes:0},bm=1e7,xm={line:8,handle:8},Sm=8,Cm=1e3,wm=.02;function Tm(e,t){return e.x>=t.x&&e.x<=t.x+t.width&&e.y>=t.y&&e.y<=t.y+t.height}function Em(e){return e.type===`indicators`||e.type===`custom`}function Dm(e){return(e.actions??[]).some(e=>Em(e)||Dm(e))}var Om=class{registry=new Map;drawings=[];state=`idle`;activeTool=null;activeStyle={color:`#4c8dff`,lineWidth:1,lineStyle:`solid`,fillColor:t.LINE_TINT_FILL,fillOpacity:.12};hoverHandle=null;extents=new Map;hoverDrawing=null;creator=new tm;finishedAt=-1/0;creationPressAt=-1/0;eraser=!1;selection=new am;drag=new hm(e=>this.drawings.find(t=>t.id===e),e=>this.onScreen(e.type));eventCallback=null;requestRender=null;undoRedo=null;magnetMode=`none`;mods={ctrl:!1,shift:!1};pendingCopy=null;copies=null;copiedFrom=[];copySources=new Map;lastNudge=null;dataGetter=null;dataRevision=()=>0;displayDataGetter=null;stayInDrawingMode=!1;toolAllowed=()=>!0;toolDefaults=new Map;edits=new Map;batch=null;timeframe=null;register(e){this.registry.set(e.descriptor.type,e),this.dataGetter&&e.setDataGetter?.(this.dataGetter,this.dataRevision)}setEventCallback(e){this.eventCallback=e}setRequestRender(e){this.requestRender=e}setUndoRedoManager(e){this.undoRedo=e}setMagnetMode(e){this.magnetMode=e}getMagnetMode(){return this.magnetMode}setModifiers(e){this.mods={ctrl:e.ctrl,shift:e.shift}}activeMagnet(){return!this.mods.ctrl||this.copies?this.magnetMode:this.magnetMode===`none`?`strong`:`none`}setDataGetter(e,t=()=>0){this.dataGetter=e,this.dataRevision=t;for(let n of this.registry.values())n.setDataGetter?.(e,t)}setDisplayDataGetter(e){this.displayDataGetter=e}panes=null;setPanes(e){this.panes=e}paneAt(e){return this.panes?this.panes.paneAt(e):void 0}viewportFor(e,t){if(e===void 0)return t;let n=this.panes?.viewportOf(e)??null;return n&&t.formatTime&&!n.formatTime?{...n,formatTime:t.formatTime}:n}scopeAt(e,t){if(!this.panes&&!Tm(e,t.chartRect))return null;let n=this.paneAt(e);if(n===null)return null;let r=this.viewportFor(n,t);return r?{pane:n,viewport:r}:null}renamePanes(e){let t=!1;this.drawings=this.drawings.map(n=>{let r=n.paneId===void 0?void 0:e.get(n.paneId);return r===void 0||r===n.paneId?n:(t=!0,{...n,paneId:r})}),t&&this.requestRender?.()}onScreen(e){return bp(this.registry.get(e)?.descriptor)}anchorPoint(t,n,r){return this.onScreen(t)?Cp(n,r):{x:e.O(n.time,r),y:e.T(n.price,r)}}snapToOHLC(e,t,n,r){let i=this.activeMagnet(),a=i===`none`?[]:this.displayDataGetter?.()??this.dataGetter?.()??[];if(r!==void 0){let o=this.panes?.valuesAt;return im(e,t,i,a,e=>o?.(r,e)??[],n)}return rm(e,t,i,a,n)}dragEdit(t,n){if(!(this.registry.get(t.type)?.descriptor.creation===`freehand`||this.onScreen(t.type)))return{handleAt:(t,r,i)=>{let a=cm(r.type)&&r.anchors.length>=2&&i<r.anchors.length?r.anchors[i===0?1:i-1]:void 0;return this.mods.shift&&a?dm(a,t,n):this.snapToOHLC(e.j(t.x,n),e.M(t.y,n),n,r.paneId)},snap:e=>this.snapToOHLC(e.time,e.price,n,t.paneId)}}undo(){if(!this.undoRedo)return!1;let e=this.undoRedo.undo();return e?(this.applyUndoAction(e),!0):!1}redo(){if(!this.undoRedo)return!1;let e=this.undoRedo.redo();return e?(this.applyRedoAction(e),!0):!1}foreignHistory=null;setForeignHistory(e){this.foreignHistory=e}applyUndoAction(e){if(Em(e)){this.foreignHistory?.(e,`undo`);return}if(e.type===`drawingBatch`&&Dm(e)){for(let t of[...e.actions??[]].reverse())this.applyUndoAction(t);return}this.applyHistory(Jp(this.drawings,e))}applyRedoAction(e){if(Em(e)){this.foreignHistory?.(e,`redo`);return}if(e.type===`drawingBatch`&&Dm(e)){for(let t of e.actions??[])this.applyRedoAction(t);return}this.applyHistory(Yp(this.drawings,e))}applyHistory(e){let t=new Map(this.drawings.map((e,t)=>[e.id,{d:e,index:t}]));this.drawings=e,this.settleAfterHistory();let n=new Set(e.map(e=>e.id));for(let e of t.keys())n.has(e)||(this.edits.delete(e),this.eventCallback?.(`drawingRemove`,{id:e}));e.forEach((e,n)=>{let r=t.get(e.id);r?(r.d!==e||r.index!==n)&&this.eventCallback?.(`drawingUpdate`,{id:e.id}):this.eventCallback?.(`drawingCreate`,{id:e.id,type:e.type,drawing:e})})}settleAfterHistory(){this.dropCopyGesture(),this.selection.clear(),this.creator.reset(),this.state=this.activeTool?`creating`:`idle`,this.requestRender?.()}record(e){this.batch?this.batch.push(e):this.undoRedo?.push(e)}batchUndo(e){if(this.batch){e();return}let t=[];this.batch=t;try{e()}finally{this.batch=null}t.length===1?this.undoRedo?.push(t[0]):t.length>1&&this.undoRedo?.push({type:`drawingBatch`,before:null,after:null,actions:t})}deselect(e){this.selection.remove(e)&&!this.selection.primary&&this.state===`selected`&&(this.state=`idle`)}addToSelection(e){this.selection.add(e),this.state=`selected`}groupMates(e){let t=e.group?.id;return t?this.drawings.filter(n=>n.group?.id===t&&n.id!==e.id&&this.shown(n)).map(e=>e.id):[]}select(e){if(this.state===`creating`)return!1;let t=this.drawings.find(t=>t.id===e);return!t||!this.shown(t)?!1:(this.selection.has(e)||this.selection.only(e,this.groupMates(t)),this.state=`selected`,this.requestRender?.(),!0)}setSelectionListener(e){this.selection.setListener(e)}getSelectedDrawingIds(){return this.selection.ids()}selectInRect(e,t,n){if(this.state===`creating`)return 0;let r=this.viewportFor(n,t);if(!r)return 0;this.selection.clear(),this.state=`idle`;let i=Math.min(e.x0,e.x1),a=Math.max(e.x0,e.x1),o=Math.min(e.y0,e.y1),s=Math.max(e.y0,e.y1);for(let e of this.drawings)!this.shown(e)||e.paneId!==n||e.anchors.some(t=>{let{x:n,y:c}=this.anchorPoint(e.type,t,r);return n>=i&&n<=a&&c>=o&&c<=s})&&this.addToSelection(e.id);return this.requestRender?.(),this.getSelectedDrawingIds().length}toggleSelectionAt(e,t){if(this.state===`creating`)return!1;let n=this.scopeAt(e,t);if(!n)return!1;for(let t=this.drawings.length-1;t>=0;t--){let r=this.drawings[t];if(!(!this.shown(r)||r.paneId!==n.pane)&&this.registry.get(r.type)?.hitTest(e,r,n.viewport,8))return this.selection.has(r.id)?this.deselect([r.id]):this.addToSelection(r.id),this.requestRender?.(),!0}return!1}beginMove(e,t){this.state=`moving`;let n=this.getSelectedDrawingIds().filter(e=>e!==t.id).map(e=>this.drawings.find(t=>t.id===e)).filter(e=>e!==void 0&&!e.locked&&e.paneId===t.paneId);this.drag.beginMove(e,[t,...n])}setFlags(e,t){this.batchUndo(()=>{for(let n of e){if((t.visible===void 0||n.visible===t.visible)&&(t.locked===void 0||n.locked===t.locked))continue;let e=Y(n);Object.assign(n,t),this.record({type:`drawingModify`,before:e,after:Y(n)})}}),t.visible===!1&&this.deselect(e.map(e=>e.id)),this.requestRender?.()}lockAllDrawings(){this.setFlags(this.drawings,{locked:!0})}unlockAllDrawings(){this.setFlags(this.drawings,{locked:!1})}hideAllDrawings(){this.setFlags(this.drawings,{visible:!1})}showAllDrawings(){this.setFlags(this.drawings,{visible:!0})}setTimeframe(e){e!==this.timeframe&&(this.timeframe=e,this.deselect(this.drawings.filter(e=>!this.shown(e)).map(e=>e.id)),this.requestRender?.())}isShown(e){let t=this.drawings.find(t=>t.id===e);return t!==void 0&&this.shown(t)}onDrawnPane(e){return e.paneId===void 0||(this.panes?.viewportOf(e.paneId)??null)!==null}shown(e){return e.visible&&Oa(e.intervals,this.timeframe)&&this.onDrawnPane(e)}setDrawingVisible(e,t){let n=this.drawings.find(t=>t.id===e);return n?(this.setFlags([n],{visible:t}),t):null}setDrawingsVisible(e,t){let n=new Set(e);this.setFlags(this.drawings.filter(e=>n.has(e.id)),{visible:t})}setDrawingsLocked(e,t){let n=new Set(e);this.setFlags(this.drawings.filter(e=>n.has(e.id)),{locked:t})}setDrawingLocked(e,t){let n=this.drawings.find(t=>t.id===e);return n?(this.setFlags([n],{locked:t}),t):null}setActiveTool(e){e&&this.setEraser(!1),this.clearHover(),this.dropCopyGesture();let t=e!==this.activeTool;this.activeTool=e,this.state=e?`creating`:`idle`,this.creator.reset(),t&&this.eventCallback?.(`drawingToolChange`,{tool:e})}setStayInDrawingMode(e){this.stayInDrawingMode=e}isStayInDrawingMode(){return this.stayInDrawingMode}setToolFilter(e){this.toolAllowed=e}copySelection(){let e=this.getSelectedDrawingIds().map(e=>this.drawings.find(t=>t.id===e)).filter(e=>e!==void 0);return e.length===0?0:(ym.drawings=e.map(e=>structuredClone(e)),ym.pastes=0,e.length)}canPaste(){return this.state!==`creating`&&ym.drawings.some(e=>this.canPasteType(e.type))}canPasteType(e){return this.registry.has(e)&&this.toolAllowed(e)}paste(){if(ym.drawings.length===0||this.state===`creating`)return[];let e=ym.drawings.every(e=>this.drawings.some(t=>t.id===e.id));ym.pastes+=1;let t=e?this.computeBarOffsetTime(3*ym.pastes):0,n=[];if(this.batchUndo(()=>{for(let e of ym.drawings)this.canPasteType(e.type)&&(e.paneId!==void 0&&(!this.panes?.hasPane(e.paneId)||this.registry.get(e.type)?.descriptor.priceOnly)||n.push(this.addDrawing({...e.paneId===void 0?{}:{paneId:e.paneId},type:e.type,anchors:this.onScreen(e.type)?Dp(e.anchors,wm*ym.pastes):e.anchors.map(e=>({...e,time:e.time+t})),style:{...e.style},options:e.options?Fp(e.options):void 0,intervals:e.intervals,meta:e.meta?structuredClone(e.meta):void 0,name:e.name})))}),n.length===0)return n;this.selection.clear(),this.state=`idle`;for(let e of n)this.isShown(e)&&this.addToSelection(e);return this.requestRender?.(),n}getActiveTool(){return this.activeTool}setStyle(e){Object.assign(this.activeStyle,e)}getActiveStyle(){return{...this.activeStyle}}setSelectedDrawingStyle(e,t){let n=t?[t]:this.getSelectedDrawingIds(),r=!1;return this.batchUndo(()=>{for(let t of n){let n=this.drawings.find(e=>e.id===t);if(!n||n.locked)continue;let i=Y(n);n.style={...n.style,...e},this.record({type:`drawingModify`,before:i,after:Y(n)}),r=!0}}),r&&this.requestRender?.(),r}onPointerDown(e,t,n=xm){if(this.eraser){let r=this.scopeAt(e,t);return r?this.erase(e,r,n.line):!1}return this.state===`creating`&&this.activeTool?this.handleCreationClick(e,t):this.state===`idle`||this.state===`selected`?this.handleSelectionClick(e,t,n):!1}placeAt(e,t){let n=this.state===`creating`?this.creator.current:null;return!n||n.anchors.length!==1||this.registry.get(n.type)?.descriptor.creation===`freehand`?!1:this.handleCreationClick(e,t)}takeBackPoint(){return this.state!==`creating`||!this.creator.current?!1:(this.creator.undoPoint(),this.requestRender?.(),!0)}onPointerMove(e,t){let n=this.state===`creating`?this.creator.current:null,r=n?this.viewportFor(n.paneId,t):null;if(n&&r&&this.creator.move(this.creationAnchor(n.type,e,r,n.paneId),e))return this.requestRender?.(),!0;if(this.pendingCopy){let{pos:t}=this.pendingCopy;if(Math.hypot(e.x-t.x,e.y-t.y)<Sm)return!0;this.startCopy()}if((this.state===`moving`||this.state===`resizing`)&&this.drag.isActive()){let n=this.drawings.find(e=>e.id===this.selection.primary),r=this.viewportFor(n?.paneId,t),i=n&&r?this.dragEdit(n,r):void 0;return!r||!this.drag.move(e,r,n&&this.registry.get(n.type),i)?!1:(this.requestRender?.(),!0)}return!1}onPointerUp(){let e=this.state===`creating`?this.creator.release():null;if(e)return this.afterCreationStep(e),!0;if(this.pendingCopy)return this.toggleCopied();if(this.copies)return this.endCopy(),!0;if(this.state===`moving`||this.state===`resizing`){let e=this.drag.end();return this.batchUndo(()=>{for(let{before:t,drawing:n}of e)Lp(n.anchors,t.anchors)&&Ip(n.options,t.options)||this.record({type:`drawingModify`,before:t,after:Y(n)})}),this.state=`selected`,this.requestRender?.(),!0}return!1}beginCopyDrag(e,t,n=xm){if(this.state===`creating`||this.state===`moving`||this.state===`resizing`||this.eraser)return!1;if(this.beginHandleDrag(e,t,n))return!0;let r=this.drawingAt(e,t,n.line);return r?(this.pendingCopy={pos:e,id:r},!0):!1}beginHandleDrag(e,t,n){let r=this.scopeAt(e,t),i=this.drawings.find(e=>e.id===this.selection.primary);if(!r||!i||i.locked||!this.shown(i)||i.paneId!==r.pane)return!1;let a=this.registry.get(i.type)?.hitTestAnchor(e,i,r.viewport,n.handle)??-1;return a<0?!1:(this.state=`resizing`,this.drag.beginResize(e,i,a),!0)}dropCopyGesture(){this.pendingCopy=null;let e=this.copies;e&&(this.copies=null,this.copySources=new Map,this.drag.end(),this.drawings=this.drawings.filter(t=>!e.includes(t.id)),this.deselect(e),this.state===`moving`&&(this.state=`idle`))}startCopy(){let{pos:e,id:t}=this.pendingCopy;this.pendingCopy=null;let n=this.selection.has(t)?[t,...this.getSelectedDrawingIds().filter(e=>e!==t)]:[t],r=this.drawings.find(e=>e.id===t),i=n.map(e=>this.drawings.find(t=>t.id===e)).filter(e=>e!==void 0&&this.shown(e)&&e.paneId===r?.paneId&&this.canPasteType(e.type));if(i.length===0)return;let a=i.map(e=>{let{group:t,...n}=structuredClone(e);return{...n,id:Hp(),locked:!1}});this.copySources=new Map(a.map((e,t)=>[e.id,i[t].anchors.map(e=>({...e}))])),this.drawings=[...this.drawings,...a],this.copies=a.map(e=>e.id),this.copiedFrom=this.getSelectedDrawingIds(),this.selection.only(a[0].id,this.copies.slice(1)),this.beginMove(e,a[0]),this.requestRender?.()}endCopy(){let e=this.copies;this.copies=null,this.drag.end(),this.state=`selected`;let t=this.copySources;this.copySources=new Map;let n=e.map(e=>this.drawings.find(t=>t.id===e)).filter(e=>e!==void 0);if(n.every(e=>{let n=t.get(e.id);return!!n&&Lp(e.anchors,n)})){this.drawings=this.drawings.filter(t=>!e.includes(t.id)),this.deselect(e),this.requestRender?.();return}this.batchUndo(()=>{for(let e of n)this.record({type:`drawingCreate`,before:null,after:Y(e)})});for(let e of n)this.eventCallback?.(`drawingCreate`,{id:e.id,type:e.type,drawing:e});this.requestRender?.()}toggleCopied(){let{id:e}=this.pendingCopy;return this.pendingCopy=null,this.selection.has(e)?this.deselect([e]):this.addToSelection(e),this.requestRender?.(),!0}nudge(e,t,n){if(this.state!==`selected`)return!1;let r=this.getSelectedDrawingIds().map(e=>this.drawings.find(t=>t.id===e)).filter(e=>e!==void 0&&!e.locked&&this.shown(e));if(r.length===0||e===0&&t===0)return!1;let i=r.map(e=>e.id).join(`,`),a=Date.now(),o=this.lastNudge,s=o&&o.key===i&&a-o.at<Cm&&o.action!==null&&this.undoRedo?.last()===o.action?o:null,c=s?s.before:r.map(Y),l=r.filter(r=>{let i=this.viewportFor(r.paneId,n);return i?(r.anchors=this.onScreen(r.type)?Ep(r.anchors,e*(i.barWidth+i.barSpacing),t,i):gm(r.anchors,e,t,i),!0):!1});if(l.length===0)return!1;s&&this.undoRedo?.dropLast(),this.batchUndo(()=>{for(let e of l){let t=c.find(t=>t.id===e.id);t&&this.record({type:`drawingModify`,before:t,after:Y(e)})}}),this.lastNudge={key:i,at:a,before:c,action:this.undoRedo?.last()??null};for(let e of l)this.eventCallback?.(`drawingUpdate`,{id:e.id});return this.requestRender?.(),!0}onKeyDown(e,t=!1,n){let r=Zp(e,t,n);if(!r)return!1;let i=this.state===`selected`?this.selection.primary:null;switch(r){case`copy`:return i!==null&&this.copySelection()>0;case`paste`:return this.paste().length>0;case`duplicate`:return i!==null&&this.duplicateDrawing(i)!==null;case`group`:return i!==null&&this.groupDrawings(this.getSelectedDrawingIds())!==null;case`ungroup`:return this.ungroupSelection();case`front`:case`forward`:case`backward`:case`back`:return i!==null&&this.moveDrawing(i,r);case`undo`:return this.state===`creating`&&this.creator.current?(this.creator.undoPoint(),this.requestRender?.(),!0):this.undo();case`redo`:return this.redo();case`escape`:return this.escape();case`delete`:return i!==null&&this.removeDrawings(this.getSelectedDrawingIds())>0;case`finish`:{if(this.state!==`creating`||!this.creator.current)return!1;let e=this.creator.finish();return e===`done`?(this.afterCreationStep(e),!0):!1}}}escape(){if(this.pendingCopy||this.copies){let e=this.copies?this.copiedFrom.filter(e=>this.isShown(e)):[];return this.dropCopyGesture(),e.length>0&&(this.selection.only(e[0],e.slice(1)),this.state=`selected`),this.requestRender?.(),!0}if(this.state===`moving`||this.state===`resizing`){let e=new Map(this.drag.end().map(({before:e})=>[e.id,Y(e)]));return this.drawings=this.drawings.map(t=>e.get(t.id)??t),this.state=`selected`,this.requestRender?.(),!0}return this.eraser?(this.setEraser(!1),!0):this.state===`creating`?(this.setActiveTool(null),this.requestRender?.(),!0):this.state===`selected`?(this.selection.clear(),this.state=`idle`,this.requestRender?.(),!0):!1}ungroupSelection(){let e=new Set;for(let t of this.getSelectedDrawingIds()){let n=this.drawings.find(e=>e.id===t)?.group;n&&e.add(n.id)}for(let t of e)this.ungroup(t);return e.size>0}getDrawings(){return this.drawings}setDrawings(e){this.dropCopyGesture(),Wp(e),this.drawings=this.upgradeLegacyAnchors(e).map(e=>{let n=e.name===void 0||e.name===Pp(e.name)?e:Pm(e,Pp(e.name)),r=this.onScreen(n.type)?{...n,anchors:wp(n.anchors)}:n;if(!r.options&&r.intervals===void 0)return r;let i=(0,t.sanitizeDrawingOptions)(this.optionDefs(r.type),r.options);return{...r,options:Object.keys(i).length>0?i:void 0,intervals:ka(r.intervals)??void 0}});let n=new Map(this.drawings.map(e=>[e.id,e]));this.deselect(this.getSelectedDrawingIds().filter(e=>{let t=n.get(e);return!t||!this.shown(t)}));let r=new Set(n.keys());for(let e of[...this.edits.keys()])r.has(e)||this.edits.delete(e);this.requestRender?.()}moveDrawing(e,t){let n=this.drawings.findIndex(t=>t.id===e);if(n<0)return!1;let r=Kp(n,this.drawings.length,t);if(r===n)return!1;let i=this.drawings.map(e=>e.id),a=[...this.drawings],[o]=a.splice(n,1);return a.splice(r,0,o),this.drawings=a,this.record({type:`drawingOrder`,before:null,after:null,order:{before:i,after:a.map(e=>e.id)}}),this.eventCallback?.(`drawingUpdate`,{id:e}),this.requestRender?.(),!0}getGroups(){let e=new Map;for(let t of this.drawings){if(!t.group)continue;let n=e.get(t.group.id)??{id:t.group.id,name:t.group.name,ids:[]};n.ids.push(t.id),e.set(t.group.id,n)}return[...e.values()]}updateGroup(e,t){let n=this.drawings.filter(t=>t.group?.id===e);return n.length===0?!1:(this.batchUndo(()=>{for(let e of n){let n=Y(e);t(e),this.record({type:`drawingModify`,before:n,after:Y(e)}),this.eventCallback?.(`drawingUpdate`,{id:e.id})}}),this.requestRender?.(),!0)}groupDrawings(e,t){let n=new Set(e),r=this.drawings.filter(e=>n.has(e.id));if(r.length<2)return null;let{id:i,number:a}=Up(),o={id:i,name:Fm(t)||`Group ${a}`};return this.batchUndo(()=>{for(let e of r){let t=Y(e);e.group={...o},this.record({type:`drawingModify`,before:t,after:Y(e)}),this.eventCallback?.(`drawingUpdate`,{id:e.id})}}),this.requestRender?.(),o.id}ungroup(e){return this.updateGroup(e,e=>{delete e.group})}renameGroup(e,t){let n=Fm(t);return n.length>0&&this.updateGroup(e,t=>{t.group={id:e,name:n}})}setGroupVisible(e,t){let n=this.updateGroup(e,e=>{e.visible=t});return n&&!t&&this.deselect(this.drawings.filter(t=>t.group?.id===e).map(e=>e.id)),n}setGroupLocked(e,t){return this.updateGroup(e,e=>{e.locked=t})}priceAt(e,t,n){let r=this.drawings.find(t=>t.id===e);if(!r)return null;let i=this.registry.get(r.type)?.priceAt?.(r,t,n)??null;return i&&i.every(Number.isFinite)?i:null}hasPriceLevels(e){let t=this.drawings.find(t=>t.id===e);return!!t&&typeof this.registry.get(t.type)?.priceAt==`function`}getPlugin(e){return this.registry.get(e)??null}textBoxOf(e,t){let n=this.drawings.find(t=>t.id===e),r=n?this.viewportFor(n.paneId,t):null;return!n||!r?null:this.registry.get(n.type)?.textBox?.(n,r)??null}getDescriptor(e){return this.registry.get(e)?.descriptor??null}getOptionDefs(e){return this.optionDefs(e)??{}}optionDefs(e){return this.registry.get(e)?.descriptor.options}initialOptions(e,n){let r=this.optionDefs(e),i={...Fp(this.toolDefaults.get(e)??{}),...(0,t.sanitizeDrawingOptions)(r,n)};return Object.keys(i).length>0?i:void 0}setToolDefaults(e,n){let r=n?(0,t.sanitizeDrawingOptions)(this.optionDefs(e),n):{};Object.keys(r).length>0?this.toolDefaults.set(e,r):this.toolDefaults.delete(e)}getToolDefaults(e){return Fp(this.toolDefaults.get(e)??{})}getDrawingOptions(e){let n=this.drawings.find(t=>t.id===e);return n?(0,t.resolveDrawingOptions)(this.optionDefs(n.type),n.options):{}}setDrawingOptions(e,t){return this.updateDrawing(e,{options:t})}updateDrawing(e,n){let r=this.drawings.find(t=>t.id===e);if(!r||n.anchors&&!(n.anchors.length===r.anchors.length&&n.anchors.every(e=>Number.isFinite(e.time)&&Number.isFinite(e.price))))return!1;let i=this.edits.has(e)?null:Y(r);if(n.anchors&&(r.anchors=this.onScreen(r.type)?wp(n.anchors):n.anchors.map(e=>({time:e.time,price:e.price}))),n.style&&(r.style={...r.style,...n.style}),n.options){let e={...r.options,...(0,t.sanitizeDrawingOptions)(this.optionDefs(r.type),n.options)};r.options=Object.keys(e).length>0?e:void 0}if(n.name!==void 0){let e=Pp(n.name);e===void 0?delete r.name:r.name=e}return n.intervals!==void 0&&(r.intervals=ka(n.intervals)??void 0,!this.edits.has(e)&&!this.shown(r)&&this.deselect([e])),i&&this.record({type:`drawingModify`,before:i,after:Y(r)}),this.eventCallback?.(`drawingUpdate`,{id:e}),this.requestRender?.(),!0}beginEdit(e){let t=this.drawings.find(t=>t.id===e);return t?(this.edits.has(e)||this.edits.set(e,Y(t)),!0):!1}endEdit(e,{cancel:t=!1}={}){let n=this.edits.get(e);if(!n)return;this.edits.delete(e);let r=this.drawings.findIndex(t=>t.id===e);r<0||(t?(this.drawings[r]=n,this.requestRender?.()):JSON.stringify(n)!==JSON.stringify(this.drawings[r])&&this.record({type:`drawingModify`,before:n,after:Y(this.drawings[r])}),this.shown(this.drawings[r])||this.deselect([e]),this.eventCallback?.(`drawingUpdate`,{id:e}))}addDrawing(e){e.id&&Wp([{id:e.id}]);let t=e.id??Hp(),n={id:t,type:e.type,anchors:this.onScreen(e.type)?wp(e.anchors):e.anchors.map(e=>({...e})),style:{...this.activeStyle,...e.style},visible:e.visible??!0,locked:e.locked??!1,options:this.initialOptions(e.type,e.options),intervals:ka(e.intervals)??void 0,meta:e.meta,...typeof e.paneId==`string`?{paneId:e.paneId}:{}},r=Pp(e.name);return r!==void 0&&(n.name=r),this.drawings=[...this.drawings,n],this.record({type:`drawingCreate`,before:null,after:Y(n)}),this.eventCallback?.(`drawingCreate`,{id:t,type:n.type,drawing:n}),this.requestRender?.(),t}upgradeLegacyAnchors(e){let t=this.dataGetter?.();if(!t||t.length===0)return e;let n=bm;return t[t.length-1].time<n?e:e.map(e=>this.onScreen(e.type)?e:{...e,anchors:e.anchors.map(e=>{if(!Number.isFinite(e.time)||e.time<0||e.time>=n)return e;let r=Math.max(0,Math.min(t.length-1,Math.round(e.time)));return{...e,time:t[r].time}})})}removeDrawing(e){this.hoverDrawing===e&&this.clearHover();let t=this.drawings.findIndex(t=>t.id===e),n=this.drawings[t];this.drawings=this.drawings.filter(t=>t.id!==e),n&&this.record({type:`drawingRemove`,before:structuredClone(n),after:null,index:t}),this.deselect([e]),this.edits.delete(e),this.eventCallback?.(`drawingRemove`,{id:e}),this.requestRender?.()}removeDrawings(e){let t=[...new Set(e)].filter(e=>{let t=this.drawings.find(t=>t.id===e);return t!==void 0&&!t.locked});return t.length===0?0:(this.batchUndo(()=>{for(let e of t)this.removeDrawing(e)}),t.length)}amendNew(e,t){let n=this.drawings.find(t=>t.id===e);if(!n)return!1;let r=this.undoRedo?.last();if(!this.undoRedo||r?.type!==`drawingCreate`||r.after?.id!==e)return this.updateDrawing(e,t);let i=[],a=this.batch;this.batch=i;let o=!1;try{o=this.updateDrawing(e,t)}finally{this.batch=a}return o?(this.undoRedo.replaceLast({...r,after:Y(n)}),!0):!1}takeBack(e){let t=this.undoRedo?.last();if(!this.undoRedo||t?.type!==`drawingCreate`||t.after?.id!==e){this.removeDrawing(e);return}this.undoRedo.dropLast(),this.drawings=this.drawings.filter(t=>t.id!==e),this.deselect([e]),this.edits.delete(e),this.eventCallback?.(`drawingRemove`,{id:e}),this.requestRender?.()}duplicateDrawing(e){let t=this.drawings.find(t=>t.id===e);if(!t)return null;let n=structuredClone(t);n.id=Hp();let r=this.computeBarOffsetTime(3);return n.anchors=this.onScreen(n.type)?Dp(n.anchors,wm):n.anchors.map(e=>({...e,time:e.time+r})),n.locked=!1,this.drawings.push(n),this.record({type:`drawingCreate`,before:null,after:structuredClone(n)}),this.selection.only(n.id),this.state=`selected`,this.eventCallback?.(`drawingCreate`,{id:n.id,type:n.type,drawing:n}),this.requestRender?.(),n.id}clearDrawings(){this.dropCopyGesture(),this.drawings=[],this.selection.clear(),this.state=`idle`,this.requestRender?.()}getSelectedDrawingId(){return this.selection.primary}render(t,n){t.save(),t.textAlign=`left`,t.textBaseline=`alphabetic`;let r=this.selection.primary,i=this.state===`resizing`&&r?this.drag.activeHandle():-1;gp({primary:r,hover:this.hoverHandle,drag:i>=0&&r?{id:r,index:i}:null});let a=new Map;this.extents=a;try{for(let e of this.drawings){if(!this.shown(e))continue;let r=this.registry.get(e.type),i=this.viewportFor(e.paneId,n);if(!r||!i)continue;mn();let o=null;try{Nm(t,r,e,i,this.selection.has(e.id))}finally{o=gn()}o&&a.set(e.id,o)}let r=this.creator.previewState(),i=r?this.registry.get(r.type):void 0,o=r?this.viewportFor(r.paneId,n):null;if(r&&i&&o&&(gp({primary:r.id,hover:null,drag:null}),Nm(t,i,r,o,!0),r.anchors.length<2)){let n=o;yp(t,r,r.anchors.map(t=>this.onScreen(r.type)?Cp(t,n):{x:e.O(t.time,n),y:e.T(t.price,n)}))}}finally{gp(null)}t.restore()}computeBarOffsetTime(e){let t=this.dataGetter?.();if(!t||t.length<2)return e;let n=Math.max(0,t.length-20),r=[];for(let e=n+1;e<t.length;e++)r.push(t[e].time-t[e-1].time);return r.length===0?e:(r.sort((e,t)=>e-t),e*r[Math.floor(r.length/2)])}creationAnchor(t,n,r,i){if(this.onScreen(t))return Tp(n,r);let a=e.j(n.x,r),o=e.M(n.y,r);if(this.registry.get(t)?.descriptor.creation===`freehand`)return{time:a,price:o};let s=this.creator.current?.anchors,c=s&&s.length>0?s[s.length-1]:void 0;return this.mods.shift&&c&&cm(t)?dm(c,n,r):this.snapToOHLC(a,o,r,i)}handleCreationClick(e,t){let n=this.activeTool,r=n?this.registry.get(n):void 0;if(!n||!r)return!1;let i=this.creator.current,a=i?i.paneId:this.paneAt(e);if(a===null||a!==void 0&&r.descriptor.priceOnly)return!1;let o=this.viewportFor(a,t);if(!o)return!1;let s=()=>({id:Hp(),type:n,anchors:[],style:{...this.activeStyle},visible:!0,locked:!1,options:this.initialOptions(n),...a===void 0?{}:{paneId:a}});return this.creationPressAt=Date.now(),this.afterCreationStep(this.creator.press(r,s,this.creationAnchor(n,e,o,a),e,e=>this.anchorPoint(n,e,o))),!0}afterCreationStep(e){e===`done`?this.finalizeCreation():e===`cancel`&&this.creator.reset(),this.requestRender?.()}setEraser(e){e!==this.eraser&&(this.eraser=e,this.clearHover(),e&&(this.setActiveTool(null),this.selection.clear(),this.state=`idle`),this.eventCallback?.(`toolModeChange`,{eraser:e}),this.requestRender?.())}isEraser(){return this.eraser}erase(e,t,n){let r=this.erasableAt(e,t,n);return r?(this.removeDrawing(r),!0):!1}erasableAt(e,t,n=xm.line){for(let r=this.drawings.length-1;r>=0;r--){let i=this.drawings[r];if(!(!this.shown(i)||i.locked||i.paneId!==t.pane)&&this.registry.get(i.type)?.hitTest(e,i,t.viewport,n))return i.id}return null}justFinished(e=500){return Date.now()-this.creationPressAt<e&&this.finishedAt>=this.creationPressAt}finalizeCreation(){let e=this.creator.take();if(e){if(this.finishedAt=Date.now(),this.drawings.push(e),this.selection.only(e.id),this.record({type:`drawingCreate`,before:null,after:structuredClone(e)}),this.eventCallback?.(`drawingCreate`,{id:e.id,type:e.type,drawing:e,drawn:!0}),this.stayInDrawingMode&&this.activeTool){this.selection.clear(),this.state=`creating`;return}this.activeTool=null,this.state=`selected`,this.eventCallback?.(`drawingToolChange`,{tool:null})}}isDragging(){return this.state===`moving`||this.state===`resizing`}drawingAt(e,t,n=xm.line){let r=this.scopeAt(e,t);if(!r)return null;for(let t=this.drawings.length-1;t>=0;t--){let i=this.drawings[t];if(!(!this.shown(i)||i.paneId!==r.pane)&&this.registry.get(i.type)?.hitTest(e,i,r.viewport,n))return i.id}return null}hoverCursorAt(e,t){let n=this.hoverAt(e,t),r=n.handle?.id!==this.hoverHandle?.id||n.handle?.index!==this.hoverHandle?.index;return this.hoverHandle=n.handle,this.hoverDrawing=n.drawing,r&&this.requestRender?.(),n.cursor}drawnExtent(e){return this.extents.get(e)??null}clearHover(){let e=this.hoverHandle;this.hoverHandle=null,this.hoverDrawing=null,e&&this.requestRender?.()}renderHover(e,t){let n=this.hoverDrawing;if(!n||this.selection.has(n)&&!this.eraser||this.activeTool||this.state===`creating`)return;let r=this.drawings.find(e=>e.id===n);if(!r||r.locked||!this.shown(r))return;let i=this.registry.get(r.type),a=this.viewportFor(r.paneId,t);i&&a&&Nm(e,i,r,a,!1,!0)}axisSpans(e){let t=this.creator.previewState(),n=t??(this.selection.primary?this.drawings.find(e=>e.id===this.selection.primary):void 0);if(!n||!t&&!this.shown(n))return[];let r=this.registry.get(n.type),i=this.viewportFor(n.paneId,e),a=r&&i?vm(n,r.descriptor):null;return a&&i?[{...a,color:n.style.color,viewport:i}]:[]}hoverAt(e,t){let n={cursor:null,handle:null,drawing:null},r=this.scopeAt(e,t);if(!r)return n;if(this.eraser){let t=this.erasableAt(e,r);return{...n,cursor:t?`pointer`:null,drawing:t}}if(this.activeTool||this.state===`creating`)return n;let i=xm.handle,a=r.viewport;if(this.selection.primary){let t=this.drawings.find(e=>e.id===this.selection.primary),n=t&&this.shown(t)&&!t.locked&&t.paneId===r.pane?this.registry.get(t.type):void 0,o=t&&n?n.hitTestAnchor(e,t,a,i):-1;if(t&&o>=0)return{cursor:`move`,handle:{id:t.id,index:o},drawing:t.id}}for(let t=this.drawings.length-1;t>=0;t--){let n=this.drawings[t];if(!(!this.shown(n)||n.locked||n.paneId!==r.pane)&&this.registry.get(n.type)?.hitTest(e,n,a,xm.line))return{cursor:`pointer`,handle:null,drawing:n.id}}return n}handleSelectionClick(e,t,n){let r=n.line,i=this.scopeAt(e,t);if(!i)return!1;let a=i.viewport;if(this.selection.primary){let t=this.drawings.find(e=>e.id===this.selection.primary);if(t&&this.shown(t)&&!t.locked&&t.paneId===i.pane){let i=this.registry.get(t.type);if(i){let o=i.hitTestAnchor(e,t,a,n.handle);if(o>=0)return this.state=`resizing`,this.drag.beginResize(e,t,o),!0;if(i.hitTest(e,t,a,r))return this.beginMove(e,t),!0}}}for(let t=this.drawings.length-1;t>=0;t--){let n=this.drawings[t];if(!this.shown(n)||n.paneId!==i.pane)continue;let o=this.registry.get(n.type);if(o&&o.hitTest(e,n,a,r))return this.selection.has(n.id)?this.selection.focus(n.id):this.selection.only(n.id,this.groupMates(n)),this.requestRender?.(),n.locked?(this.state=`selected`,!1):(this.beginMove(e,n),!0)}return this.selection.primary&&(this.selection.clear(),this.state=`idle`,this.requestRender?.()),!1}},km=.55,Am=6,jm=[`fill`,`fillRect`,`fillText`,`strokeText`];function Mm(e,n){e.shadowColor=(0,t.withAlpha)(n,km),e.shadowBlur=Am;let r=e;for(let e of jm)r[e]=()=>void 0;return()=>{for(let e of jm)delete r[e]}}function Nm(e,t,n,r,i,a=!1){let o=r.chartRect;e.save(),e.beginPath(),e.rect(o.x,o.y,o.width,o.height),e.clip(),vn(o);let s=a?Mm(e,n.style.color):null;try{t.render(e,n,r,i)}finally{s?.(),vn(null),e.restore()}}function Pm(e,t){let{name:n,...r}=e;return t===void 0?r:{...r,name:t}}function Fm(e){return(e??``).trim().slice(0,80)}var Im=class{keepOut=null;formatTime=null;constructor(e){this.manager=e}setKeepOut(e){this.keepOut=e}setTimeFormat(e){this.formatTime=e}getKeepOut(){return this.keepOut?.()??[]}renderHover(e,t,n){zn(n??null);try{this.manager.renderHover(e,t)}finally{zn(null)}}axisSpans(e){return this.manager.axisSpans(e)}render(e,t,n){zn(n??null),Jn(this.getKeepOut());try{this.manager.render(e,this.formatTime?{...t,formatTime:this.formatTime}:t)}finally{Jn(null),zn(null)}}};function Lm(e,t,n){let r=Math.max(0,t),i=Math.min(e.length-1,n);if(i<=r)return null;let a=r,o=r;for(let t=r;t<=i;t++)e[t].high>e[a].high&&(a=t),e[t].low<e[o].low&&(o=t);if(a===o)return null;let s={time:e[a].time,price:e[a].high},c={time:e[o].time,price:e[o].low};return a<o?[s,c]:[c,s]}var Rm={0:`#787b86`,.236:`#e8505b`,.25:`#e8505b`,.382:`#d97a0e`,.5:`#1a9a6a`,.618:`#0e93a3`,.75:`#2f7fd8`,.786:`#5b6cf0`,1:`#787b86`,1.272:`#b25ad1`,1.414:`#d6487f`,1.618:`#2f7fd8`,2:`#7a5cff`,2.618:`#e8505b`,3.618:`#b25ad1`,4.236:`#d6487f`};function zm(e,t=[]){return Bm(e,t).map(e=>{let t=Rm[e.value];return t?{...e,color:t}:e})}function Bm(e,t=[]){return[...e.map(e=>({value:e,visible:!0})),...t.map(e=>({value:e,visible:!1}))].sort((e,t)=>e.value-t.value)}function Vm(e=!1,t=!1){return{extendLeft:{kind:`boolean`,label:`Extend left`,default:e},extendRight:{kind:`boolean`,label:`Extend right`,default:t}}}var Hm={showPrice:{kind:`boolean`,label:`Show price`,default:!0}},Um={trendLine:{kind:`boolean`,label:`Trend line`,default:!0},oneColor:{kind:`boolean`,label:`Use one color`,default:!1}},Wm={showLevels:{kind:`boolean`,label:`Show levels`,default:!0},showPrices:{kind:`boolean`,label:`Show prices`,default:!0},labelPosition:{kind:`choice`,label:`Labels`,default:`left`,choices:[{value:`left`,label:`Left`},{value:`right`,label:`Right`}]}};function Gm(e,t){let n=e.textBackground??t.box,r=e.textBorder??t.border,i=!t.fill&&!e.fillColor?void 0:P(e);return{fontSize:Sn(e),color:e.textColor??kn(e.color),fill:n&&i?i:void 0,stroke:r?e.borderColor??e.color:void 0,maxWidth:e.textWrap===void 0?t.width:e.textWrap>0?e.textWrap:1/0,bold:e.bold,italic:e.italic,align:e.textAlign}}var Km=1.3,qm=12,Jm=3;function Ym(e,t=!1,n=!1,r=!0){let i=M();return`${n?`italic `:``}${t?`bold `:``}${e}px ${r?i.prose:i.figures}`}function Xm(e,t,n,r=qm){let i=[];for(let a of t.split(`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./gpuContexts-BN9YuYEa.cjs`);let t=require(`@tradecanvas/commons`);function n(e){e.style.fontFeatureSettings=`normal`}var r=class{canvas;ctx;dpr=1;constructor(e,t){this.canvas=document.createElement(`canvas`),this.canvas.style.position=`absolute`,this.canvas.style.top=`0`,this.canvas.style.left=`0`,this.canvas.style.zIndex=String(t),this.canvas.style.pointerEvents=`none`,n(this.canvas),this.ctx=this.canvas.getContext(`2d`),e.appendChild(this.canvas)}resize(e,t){this.dpr=t;let n=Math.round(e.width*t),r=Math.round(e.height*t);(this.canvas.width!==n||this.canvas.height!==r)&&(this.canvas.width=n,this.canvas.height=r),this.canvas.style.width=`${e.width}px`,this.canvas.style.height=`${e.height}px`,this.ctx.setTransform(t,0,0,t,0,0)}clear(){this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.setTransform(this.dpr,0,0,this.dpr,0,0)}getSize(){return{width:this.canvas.width/this.dpr,height:this.canvas.height/this.dpr}}destroy(){this.canvas.width=0,this.canvas.height=0,this.canvas.remove()}},i=class{scene=null;top=null;back=null;gpuCanvas=null;size=null;dpr=1;constructor(e){this.container=e}createLayers(){this.destroy(),this.scene=new r(this.container,0),this.top=new r(this.container,1)}getLayer(e){return(e===t.LayerType.Hover?this.top:this.scene)??void 0}backLayer(){return this.gpuCanvas?(this.back||(this.back=new r(this.container,0),this.container.insertBefore(this.back.canvas,this.gpuCanvas),this.size&&this.back.resize(this.size,this.dpr)),this.back):null}getDpr(){return this.dpr}dropBackLayer(){this.back?.destroy(),this.back=null}attachGpu(e){this.detachGpu(),e.style.position=`absolute`,e.style.top=`0`,e.style.left=`0`,e.style.zIndex=`0`,e.style.pointerEvents=`none`,this.container.insertBefore(e,this.scene?.canvas??null),this.gpuCanvas=e,this.size&&this.sizeGpu(this.size,this.dpr)}detachGpu(){this.dropBackLayer(),this.gpuCanvas&&(this.gpuCanvas.width=0,this.gpuCanvas.height=0,this.gpuCanvas.remove()),this.gpuCanvas=null}resize(e,t){this.size=e,this.dpr=t,this.scene?.resize(e,t),this.top?.resize(e,t),this.back?.resize(e,t),this.sizeGpu(e,t)}destroy(){this.detachGpu(),this.scene?.destroy(),this.top?.destroy(),this.scene=null,this.top=null}sizeGpu(e,t){let n=this.gpuCanvas;if(!n)return;let r=Math.round(e.width*t),i=Math.round(e.height*t);(n.width!==r||n.height!==i)&&(n.width=r,n.height=i),n.style.width=`${e.width}px`,n.style.height=`${e.height}px`}},a=class{animFrameId=0;running=!1;paused=!1;dirtyLayers=new Set;swapLayers=new Set;callback=null;setCallback(e){this.callback=e}markDirty(e){this.dirtyLayers.add(e),this.running&&!this.paused&&!this.animFrameId&&this.scheduleFrame()}markAllDirty(){this.dirtyLayers.add(t.LayerType.Background),this.dirtyLayers.add(t.LayerType.Main),this.dirtyLayers.add(t.LayerType.Overlay),this.dirtyLayers.add(t.LayerType.UI),this.dirtyLayers.add(t.LayerType.Hover),this.running&&!this.paused&&!this.animFrameId&&this.scheduleFrame()}start(){this.running=!0,this.markAllDirty()}pause(){this.paused=!0,this.animFrameId&&=(cancelAnimationFrame(this.animFrameId),0)}resume(){this.paused&&(this.paused=!1,this.running&&this.dirtyLayers.size>0&&!this.animFrameId&&this.scheduleFrame())}isPaused(){return this.paused}stop(){this.running=!1,this.animFrameId&&=(cancelAnimationFrame(this.animFrameId),0)}scheduleFrame(){this.animFrameId=requestAnimationFrame(()=>{if(this.animFrameId=0,!(!this.running||!this.callback)&&this.dirtyLayers.size>0){let e=this.dirtyLayers;this.dirtyLayers=this.swapLayers,this.callback(e),e.clear(),this.swapLayers=e}})}},o=2;function s(e=2){let t=typeof window<`u`&&window.devicePixelRatio||1;return e>0?Math.min(t,e):t}var c=class{observer=null;callback=null;currentDpr=1;resizeScheduled=!1;cachedSize;stopWatchingRatio=null;constructor(e,t=2){this.container=e,this.maxPixelRatio=t,this.currentDpr=s(t),this.cachedSize={width:e.clientWidth,height:e.clientHeight}}getDpr(){return this.currentDpr}getMaxPixelRatio(){return this.maxPixelRatio}setMaxPixelRatio(e){this.maxPixelRatio=e,this.update(!0)}getContainerSize(){return this.cachedSize}readContainerSize(){let e=this.container.clientWidth,t=this.container.clientHeight;return(e!==this.cachedSize.width||t!==this.cachedSize.height)&&(this.cachedSize={width:e,height:t}),this.cachedSize}onResize(e){this.callback=e,this.observer=new ResizeObserver(()=>{this.resizeScheduled||(this.resizeScheduled=!0,requestAnimationFrame(()=>{this.resizeScheduled=!1,this.update(!1)}))}),this.observer.observe(this.container),this.watchRatio()}update(e){let t=s(this.maxPixelRatio),n=this.container.clientWidth,r=this.container.clientHeight,i=t!==this.currentDpr||n!==this.cachedSize.width||r!==this.cachedSize.height;this.currentDpr=t,this.cachedSize={width:n,height:r},(i||e)&&this.callback?.(this.cachedSize,t)}watchRatio(){if(this.stopWatchingRatio?.(),this.stopWatchingRatio=null,typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(resolution: ${window.devicePixelRatio||1}dppx)`);if(!e||typeof e.addEventListener!=`function`)return;let t=()=>{this.update(!1),this.watchRatio()};e.addEventListener(`change`,t),this.stopWatchingRatio=()=>e.removeEventListener(`change`,t)}destroy(){this.observer?.disconnect(),this.observer=null,this.stopWatchingRatio?.(),this.stopWatchingRatio=null,this.callback=null}};function l(e,n,r,i){let a=n.scaleMode??(n.logScale?`logarithmic`:`regular`);return(a===`percentage`||a===`indexedTo100`)&&n.scaleBaseline?(0,t.formatPriceScaleLabel)(e,a,n.scaleBaseline,r,i):n.formatPrice?n.formatPrice(e):(0,t.formatPriceScaleLabel)(e,`regular`,void 0,r,i)}function u(e,t,n){return n!==null&&n>0?Math.max(1,Math.ceil(e/n-1e-9))*n:t===null?e:Math.max(e,10**-t)}var d=1e-9;function f(e,t){for(let n=0;n<t;n++){let t=10**n;if(e.every(e=>Math.abs(e*t-Math.round(e*t))<=d*Math.max(1,Math.abs(e*t))))return n}return t}function p(e,t,n){return Math.floor(t/n+1e-9)-Math.ceil(e/n-1e-9)+1}function m(e,t){if(!t||!(t>0)||e>=1)return e;let n=t;for(;n<e;)n*=2;return n}var h=24,g=200;function _(e){return Math.max(2,Math.min(h,Math.round(e/56)+1))}function v(e){if(!(e>0))return 0;let t=10**Math.floor(Math.log10(e)+1e-9),n=e/t;return(n<2?1:n<5?2:5)*t}function y(e){let t=10**Math.floor(Math.log10(e)+1e-9),n=e/t;return(n<1.5?2:n<3.5?5:10)*t}function b(e){return e<1?Math.ceil(-Math.log10(e))+1:+(e<10)}function x(e,n,r){let i=(0,t.computeTickStep)(e,n,_(r));if(!(i>0)||!(r>0))return i;let a=n-e;for(let e=0;e<8&&i/a*r<30;e++)i=y(i);return i}function S(e,t,n){if(!(n>0)||!(t>=e))return[];let r=[],i=Math.ceil(e/n-1e-9);if(!Number.isFinite(i)||Math.abs(i)>=2**53-1)return[];for(let e=i;e*n<=t+n*1e-9&&e-i<g;e++){let t=e*n;r.push(Math.abs(t)<n*1e-9?0:t)}return r}var C=12,w=14,T=class{locale=`en-US`;reservedPrice=null;precision=null;tick=null;rows=[];setPricePrecision(e){this.precision=e!==null&&Number.isInteger(e)&&e>=0?e:null}setPriceTick(e){this.tick=e!==null&&Number.isFinite(e)&&e>0?e:null}scale(e){let{min:n,max:r}=e.priceRange,i=x(n,r,e.chartRect.height),a=(0,t.autoPricePrecision)(n,r);if(e.priceUnit)return{step:m(i,e.priceUnit),precision:this.precision??a};let o=u(i,this.precision,this.tick);return p(n,r,o)<2?{step:i,precision:Math.max(this.precision??0,a)}:{step:o,precision:this.precision??a}}ticks(e){let{min:t,max:n}=e.priceRange;if(!(n-t>0))return[];let r=e.scaleMode??(e.logScale?`logarithmic`:`regular`),i=e.scaleBaseline;return(r===`percentage`||r===`indexedTo100`)&&i?this.rebasedTicks(e,r,i):r===`logarithmic`&&t>0?this.logTicks(e):S(t,n,this.scale(e).step)}rebasedTicks(e,t,n){let{min:r,max:i}=e.priceRange,a=t===`percentage`?100:0,o=e=>e/n*100-a,s=e=>(e+a)/100*n,c=Math.min(o(r),o(i)),l=Math.max(o(r),o(i));return S(c,l,x(c,l,e.chartRect.height)).map(s).sort((e,t)=>e-t)}logTicks(t){let{min:n,max:r}=t.priceRange,i=Math.log(r/n)/t.chartRect.height,a=e.E(t),o=Math.exp(-i*56),s=[],c=u(v(r*(1-o)),this.precision,this.tick),l=Math.floor(r/c+1e-9)*c,d=null;for(let e=0;e<200&&l>=n&&l>0;e++){let e=a(l);(d===null||Math.abs(e-d)>=30)&&(s.push(l),d=e);let t=l*o;if(c=u(v(Math.min(l-t,t)),this.precision,this.tick),!(c>0))break;let n=Math.round(t/c)*c;n>=l&&(n-=c),l=n}return s.length===0?S(n,r,this.scale(t).step):s.reverse()}labelText(e,t){return l(e,t,this.scale(t).precision,this.locale)}setReservedPriceProvider(e){this.reservedPrice=e}setLocale(e){this.locale=e}labelRows(){return this.rows}render(t,n,r,i=`right`,a=[]){let{chartRect:o,priceRange:s}=n,c=i===`left`,u=c?o.x:o.x+o.width;if(s.max-s.min<=0)return;let d=e.E(n);t.strokeStyle=r.style?.axis.price.line??r.axisLine,t.lineWidth=1,t.globalAlpha=.65,t.beginPath(),t.moveTo(u+.5,o.y),t.lineTo(u+.5,o.y+o.height),t.stroke(),t.globalAlpha=1;let{precision:p}=this.scale(n),m=this.ticks(n),h=n.scaleMode??(n.logScale?`logarithmic`:`regular`),g=h===`regular`||h===`logarithmic`?f(m,p):p,_=`500 ${r.font.sizeSmall}px ${r.font.family}`,v=[],y=c?null:this.reservedPrice?.()??null,b=y===null?null:e.T(y,n);for(let e of m){let t=d(e);b!==null&&Math.abs(t-b)<C||a.some(e=>Math.abs(t-e)<w)||v.push({y:t,text:l(e,n,g,this.locale)})}t.font=_,t.textBaseline=`middle`,t.textAlign=c?`right`:`left`,t.strokeStyle=r.style?.axis.price.line??r.axisLine,t.globalAlpha=.45,t.beginPath();let x=c?-1:1;for(let{y:e}of v)t.moveTo(u+x,e+.5),t.lineTo(u+4*x,e+.5);t.stroke(),t.globalAlpha=1,t.fillStyle=r.style?.axis.price.text??r.axisLabel;for(let{y:e,text:n}of v)t.fillText(n,u+8*x,e);c||(this.rows=v.map(e=>e.y))}};function E(e,t,n){let r=e.shape?.tagRadius;return typeof r==`number`&&Number.isFinite(r)?Math.max(0,Math.min(r,n/2,t/2)):0}function D(e,t,n,r,i,a){let o=E(a,r,i);if(e.beginPath(),!(o>0)){e.rect(t,n,r,i);return}e.moveTo(t+o,n),e.lineTo(t+r-o,n),e.arcTo(t+r,n,t+r,n+o,o),e.lineTo(t+r,n+i-o),e.arcTo(t+r,n+i,t+r-o,n+i,o),e.lineTo(t+o,n+i),e.arcTo(t,n+i,t,n+i-o,o),e.lineTo(t,n+o),e.arcTo(t,n,t+o,n,o),e.closePath()}function O(e,t,n,r,i,a){if(!(E(a,r,i)>0)){e.fillRect(t,n,r,i);return}D(e,t,n,r,i,a),e.fill()}function k(e){let t=Math.abs(e);return t>=1e3?1:t>=1?2:t>=.01?4:6}var A=16;function j(e,t,n,r=16){let i=r/2,a=e.map(e=>Math.min(Math.max(e,t+i),n-i));for(let e=1;e<a.length;e++)a[e]=Math.max(a[e],a[e-1]+r);a.length>0&&(a[a.length-1]=Math.min(a[a.length-1],n-i));for(let e=a.length-2;e>=0;e--)a[e]=Math.min(a[e],a[e+1]-r);if(a.length>0&&a[0]<t+i){a[0]=t+i;for(let e=1;e<a.length;e++)a[e]=Math.max(a[e],a[e-1]+r)}return a}function ee(e){let t=te(e);if(!t)return`#ffffff`;let[n,r,i]=t;return(.299*n+.587*r+.114*i)/255>.62?`#10131a`:`#ffffff`}function te(e){let t=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(t){let e=t[1].length===3?t[1].replace(/./g,e=>e+e):t[1];return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}let n=/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i.exec(e.trim());return n?[Number(n[1]),Number(n[2]),Number(n[3])]:null}function ne(e,t,n=[],r=16){let i=r/2,a=n.filter(e=>e.y+e.half>t.top&&e.y-e.half<t.bottom).sort((e,t)=>e.y-t.y),o=e.filter(e=>e.y>=t.top&&e.y<=t.bottom).sort((e,t)=>e.y-t.y),s=[],c=0,l=t.top;for(let e=0;e<=a.length;e++){e>0&&(l=Math.max(l,a[e-1].y+a[e-1].half));let n=l,u=e===a.length?t.bottom:a[e].y-a[e].half,d=e===a.length?1/0:a[e].y,f=c;for(;c<o.length&&o[c].y<d;)c++;let p=o.slice(f,c);if(p.length===0||u-n<r)continue;let m=j(p.map(e=>e.y),n,u,r);p.forEach((e,t)=>{m[t]-i>=n-.5&&m[t]+i<=u+.5&&s.push({...e,y:m[t]})})}return s}function re(e,t,n,r,i){if(t.length!==0){e.save(),e.font=`bold ${i.font.sizeSmall}px ${i.font.family}`,e.textBaseline=`middle`,e.textAlign=`left`;for(let a of t){let t=Math.min(e.measureText(a.text).width+10,r-2);e.fillStyle=a.color,O(e,n+1,Math.round(a.y-8),t,16,i),e.fillStyle=ee(a.color),e.fillText(a.text,n+5,Math.round(a.y))}e.restore()}}function ie(e,t,n,r,i,a){re(e,ne(t,i),n,r,a)}function ae(e){return{plot:e,plotText:null,panes:new Map}}function oe(e,t,n,r){let i=e.region(t),a=0;for(;a<n.length&&i.step(n[a]);)a++;let o=new Map;for(let t of r){let n=e.region(t.rect).step(t.background),r=e.region(t.inner),i=0;if(n)for(;i<t.steps.length&&r.step(t.steps[i]);)i++;o.set(t.id,{background:n,text:r,rest:t.steps.slice(i)})}return{plot:n.slice(a),plotText:i,panes:o}}var se=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange,s=r.barWidth,c=s+r.barSpacing,l=-r.offset+r.chartRect.x+s/2,{min:u,max:d}=r.priceRange;if(d-u===0)return;if(e.f(r)){e.p(t,n,r,i.candleUp,i.candleDown);return}let f=e.E(r);e.v(t,r=>{let{body:u,wick:d}=e.h(s,r.ratio),p=(u-d)/2,m=new Path2D,h=new Path2D,g=new Path2D,_=new Path2D;for(let e=a;e<=o&&e<n.length;e++){let t=n[e],i=t.close>=t.open,a=r.left(e*c+l,d),o=r.y(f(t.high)),s=r.y(f(t.low));(i?m:h).rect(a,Math.min(o,s),d,Math.max(Math.abs(s-o),1));let v=r.y(f(t.open)),y=r.y(f(t.close));(i?g:_).rect(a-p,Math.min(v,y),u,Math.max(Math.abs(y-v),d))}t.fillStyle=i.candleUpWick,t.fill(m),t.fillStyle=i.candleDownWick,t.fill(h),t.fillStyle=i.candleUp,t.fill(g),t.fillStyle=i.candleDown,t.fill(_)})}};function ce(e){if(e.style)return e.style.crosshair;let t=()=>({visible:!0,color:e.crosshair,style:`solid`,width:1});return{horizontal:t(),vertical:t(),labelBackground:e.text,labelText:e.background}}var le=16,ue=class{visible=!0;timeframeMs=0;setVisible(e){this.visible=e}isVisible(){return this.visible}setTimeframeMs(e){this.timeframeMs=e}isShown(e){return this.remaining(e)>0}render(e,t,n,r,i=null){let a=this.remaining(r);if(i===null||a<=0)return;let o=i.y+i.height;e.fillStyle=i.color,O(e,i.x,o,i.width,16,n),e.font=`${n.font.sizeSmall}px ${n.font.family}`,e.textBaseline=`middle`,e.textAlign=`left`,e.fillStyle=ee(i.color),e.fillText(this.formatRemaining(a),i.x+5,o+16/2)}remaining(e){if(!this.visible||!(this.timeframeMs>0)||e.length===0)return 0;let n=e[e.length-1].time*(0,t.barTimeUnit)(e)+this.timeframeMs-Date.now();return n>0?n:0}formatRemaining(e){let t=Math.ceil(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`:`${r}:${String(i).padStart(2,`0`)}`}};function de(e,t,n){let r=e.map(e=>e.y);if(e.length===0)return r;let i=t!==null&&e[t]?t:fe(e),a=e.map((e,t)=>t).filter(e=>e!==i),o=e[i].y,s=a.filter(t=>e[t].y<=o).sort((t,n)=>e[n].y-e[t].y),c=a.filter(t=>e[t].y>o).sort((t,n)=>e[t].y-e[n].y),l=r[i]-e[i].above;for(let t of s)r[t]+e[t].below>l&&(r[t]=l-e[t].below),l=r[t]-e[t].above;let u=r[i]+e[i].below;for(let t of c)r[t]-e[t].above<u&&(r[t]=u+e[t].above),u=r[t]+e[t].below;return n?r.map((t,r)=>t!==e[r].y&&(t-e[r].above<n.top||t+e[r].below>n.bottom)?NaN:t):r}function fe(e){let t=e.map(e=>e.y),n=(Math.min(...t)+Math.max(...t))/2,r=0;return t.forEach((e,i)=>{Math.abs(e-n)<Math.abs(t[r]-n)&&(r=i)}),r}var pe=20,me=8,he=14,ge=10,_e=8,ve=`#000`,ye=2,be=4.5;function xe(e,n){let r=n?.priceLimits??(n?.background&&Se(n.background)?t.LIGHT_PRICE_LIMITS:t.DARK_PRICE_LIMITS),i=e=>n?.background&&n.text?Te(e,n.background,n.text):e;return[{price:e.ceiling,color:i(e.colors?.ceiling??r.ceiling),label:`CE`},{price:e.floor,color:i(e.colors?.floor??r.floor),label:`FL`},{price:e.reference,color:i(e.colors?.reference??r.reference),label:`REF`}]}function Se(e){return(0,t.inkOn)(e,`#000000`,`#ffffff`)===`#000000`}var Ce=new Map,we=64;function Te(e,n,r){let i=`${e}|${n}|${r}`,a=Ce.get(i);return a===void 0&&(Ce.size>=we&&Ce.clear(),a=(0,t.readableOn)(e,n,r,be),Ce.set(i,a)),a}function Ee(e,t,n){if(!e)return null;let r=e.region(t,{text:!1});return n.every(e=>r.step(e))?e:null}var De=20,Oe=20,ke=class{layerManager;renderLoop;dprManager;renderCtx=null;sceneLayer;topLayer;gpu=null;lostGpu=null;onGpuLost=null;onGpuRestored=null;onContainerResize=null;constructor(e,t){this.layerManager=new i(e),this.renderLoop=new a,this.dprManager=new c(e,t),this.layerManager.createLayers(),this.cacheLayerRefs(),this.renderLoop.setCallback(e=>this.render(e)),this.dprManager.onResize((e,t)=>{this.layerManager.resize(e,t),this.renderLoop.markAllDirty(),this.onContainerResize?.(e)});let n=this.dprManager.getContainerSize(),r=this.dprManager.getDpr();this.layerManager.resize(n,r)}cacheLayerRefs(){this.sceneLayer=this.layerManager.getLayer(t.LayerType.Main),this.topLayer=this.layerManager.getLayer(t.LayerType.Hover)}setRenderContext(e){this.renderCtx=e}attachGpu(e){this.detachGpu(),this.placeGpu(e),e.onLost(()=>{this.gpu===e&&(this.gpu=null,this.lostGpu=e,this.layerManager.detachGpu(),this.renderLoop.markAllDirty(),this.onGpuLost?.())}),e.onRestored?.(()=>{this.lostGpu===e&&(this.lostGpu=null,this.placeGpu(e),this.onGpuRestored?.())})}placeGpu(e){this.gpu=e,this.layerManager.attachGpu(e.canvas),this.renderLoop.markAllDirty()}detachGpu(){let e=this.gpu??this.lostGpu;e&&(this.gpu=null,this.lostGpu=null,this.layerManager.detachGpu(),e.destroy(),this.renderLoop.markAllDirty())}renderNow(){this.render(new Set([t.LayerType.Main,t.LayerType.Hover]))}getGpu(){return this.gpu}start(){this.renderLoop.start()}stop(){this.renderLoop.stop()}requestRender(e){e===void 0?this.renderLoop.markAllDirty():this.renderLoop.markDirty(e)}render(e){let n=this.renderCtx;if(!n)return;let{chartRect:r}=n.viewport;if(r.width<=0||r.height<=0)return;let i=!1;for(let n of e)if(n!==t.LayerType.Hover){i=!0;break}i&&this.sceneLayer&&this.renderScene(this.sceneLayer,n),this.topLayer&&this.renderTop(this.topLayer,n)}renderScene(e,n){let{viewport:r,theme:i,data:a}=n;e.clear();let o=e.ctx,s=this.gpu,c=!!s&&n.chartRenderer instanceof se,l=n.chartRenderer?[e=>n.chartRenderer.render(e,a,r,i)]:[],u=[...c?[]:l,...n.compareRenderer?[e=>n.compareRenderer.render(e,a,r,i)]:[],...n.indicatorEngine?.overlayDraws(r,n.leftViewport??void 0)??[]],d=this.paneSteps(n),f={series:!1,volume:!1,background:!1},p=ae(u);s?({drawn:f,plan:p}=this.renderGpu(s,n,o,u,d),c&&!f.series&&(p={...p,plot:[...l,...p.plot]})):this.renderBackground(o,n),o.save(),o.beginPath(),o.rect(r.chartRect.x,r.chartRect.y,r.chartRect.width,r.chartRect.height),o.clip(),s||n.depthHeatmap?.render(o,r,i),f.volume||n.volumeRenderer?.render(o,a,r,i),s||(n.volumeProfile?.render(o,a,r,i),n.marketProfile?.render(o,a,r,i)),p.plotText?.drawText(o);for(let e of p.plot)e(o);n.periodLevels?.render(o,a,r,i),n.pivotMarkers?.render(o,a,r,i),n.renderOverlayPlugins?.(o,`main`),o.restore(),this.renderPanels(o,n,d,p);let m=this.axisTagPlan(n);n.priceLimits&&this.renderPriceLimits(o,r,i,n.priceLimits,n.formatPrice,m.limits),n.tradeZoneManager?.render(o,r,i),n.drawingRenderer?.render(o,r,i),n.priceLines?.render(o,r,i,a),n.currentPriceLine?.renderLine(o,r,i),n.tradingRenderer?.render(o,r,i),n.signalMarkerManager?.render(o,r,i),n.alertManager?.render(o,r,i);let h=m.fixed,g=n.indicatorValueLabels===!1?[]:this.overlayValueTags(n,h);n.priceAxis?.render(o,r,i,`right`,[...h.map(e=>e.y),...g.map(e=>e.y)]),re(o,g,r.chartRect.x+r.chartRect.width,r.priceAxisWidth??t.PRICE_AXIS_WIDTH,i),n.leftViewport&&(n.leftPriceAxis?.render(o,n.leftViewport,i,`left`),n.indicatorValueLabels!==!1&&this.renderLeftValueLabels(o,n,n.leftViewport)),n.tradingRenderer?.renderAxisBadges(o,r,i,m.trading),n.priceLines?.renderAxisTags(o,r,i,a,m.quote),n.currentPriceLine?.renderTag(o,r,i),n.timeAxis?.render(o,r,i,a,n.timeAxisY),this.renderPanelAxes(o,n),this.renderDrawingSpans(o,n)}renderDrawingSpans(e,t){if(t.crosshairHandler?.beginSpans?.(),!(t.drawingAxisSpans===!1||!t.drawingRenderer||!t.crosshairHandler))for(let n of t.drawingRenderer.axisSpans(t.viewport))t.crosshairHandler.renderSpan(e,n,t.viewport,t.theme,t.data,t.timeAxisY)}renderGpu(t,n,r,i,a){let{viewport:o,theme:s,data:c}=n,l=this.layerManager.getDpr(),u=this.underSteps(n),d=!!(n.marketProfile?.isVisible()&&n.marketProfile.drawsText()),f=u.length>0&&!d?Ee(t.recorder?.(l,r)??null,o.chartRect,u):null,p=u.length>0&&!f,m=t.recorder?.(l,r)??null,h=m?oe(m,o.chartRect,i,a):ae(i),g=!!(n.volumeProfile?.isVisible()||n.marketProfile?.isVisible()),_=!!n.gridRenderer?.isVisible()&&!e.s(s),v=n.watermark?.isVisible()||p||_?null:{grid:n.gridRenderer?.isVisible()??!1,marks:n.gridRenderer?.isVisible()?Ae(n):void 0,rects:[...n.sessionShading?.rects(c,o,s)??[],...n.sessionBreaks?.lineRects(o,s,c)??[]]},y=n.volumeRenderer?.isVisible()&&!g?{heightRatio:n.volumeRenderer.getHeightRatio()}:null,b=t.render({data:c,viewport:o,theme:s,dpr:l,candles:n.chartRenderer instanceof se,volume:y,background:v,under:f,recorded:m,seriesRevision:n.seriesRevision}),x=b.recorded?h:ae(i),S={drawn:{...b,volume:b.volume||g},plan:x},C=v!==null&&!!b.background,w=f!==null&&b.under?[]:u;return C&&w.length===0?(this.layerManager.dropBackLayer(),S):(this.renderBackCanvas(n,w,!C),S)}underSteps(e){let{viewport:t,theme:n,data:r}=e,i=[];return e.depthHeatmap?.isVisible()&&i.push(r=>e.depthHeatmap.render(r,t,n)),(e.volumeProfile?.isVisible()||e.marketProfile?.isVisible())&&(e.volumeRenderer?.isVisible()&&i.push(i=>e.volumeRenderer.render(i,r,t,n)),e.volumeProfile?.isVisible()&&i.push(i=>e.volumeProfile.render(i,r,t,n)),e.marketProfile?.isVisible()&&i.push(i=>e.marketProfile.render(i,r,t,n))),i}renderBackCanvas(e,t,n){let r=this.layerManager.backLayer();r&&(r.clear(),n&&this.renderBackground(r.ctx,e),t.length>0&&this.inPlot(r.ctx,e.viewport,()=>t.forEach(e=>e(r.ctx))))}renderBackground(e,t){let{viewport:n,theme:r,data:i}=t;t.gridRenderer?.isVisible()&&t.gridRenderer.render(e,n,r,Ae(t)),t.sessionShading?.render(e,i,n,r),t.sessionBreaks?.renderLines(e,n,r,i),t.watermark?.render(e,n,r)}inPlot(e,t,n){e.save(),e.beginPath(),e.rect(t.chartRect.x,t.chartRect.y,t.chartRect.width,t.chartRect.height),e.clip(),n(),e.restore()}renderTop(e,t){let{viewport:n,theme:r,data:i}=t;e.clear();let a=e.ctx;t.drawingRenderer?.renderHover(a,n,r),t.measureOverlay?.render(a,n,r),t.selectionBoxOverlay?.render(a,n,r),t.crosshairHandler?.render(a,n,r),t.renderOverlayPlugins?.(a,`overlay`),this.renderPanelCrosshair(a,t),t.barCountdown?.render(a,n,r,i,t.currentPriceLine?.getTag()??null),t.crosshairHandler?.renderAxisLabels(a,n,r,i,t.timeAxisY,t.priceAxis?.labelRows(),t.timeAxis?.labelColumns()),t.priceAxisAddButton?.render(a,n,r,t.crosshairHandler?.getPosition()??null),this.renderLegend(a,t),t.renderOverlayPlugins?.(a,`ui`),this.renderPanelHoverValues(a,t)}renderLegend(e,t){if(!t.chartLegend)return;let{viewport:n,theme:r,data:i}=t,a=t.tradingRenderer?.tagRects()??[];if(a.length===0){t.chartLegend.render(e,n,r,i);return}let{x:o,y:s,width:c,height:l}=n.chartRect;e.save();try{for(let t of a)e.beginPath(),e.rect(o,s,c,l),e.rect(t.x,t.y,t.width,t.height),e.clip(`evenodd`);t.chartLegend.render(e,n,r,i)}finally{e.restore()}}paneSteps(e){let{theme:t,panels:n}=e,r=e.indicatorEngine;if(!r||n.length===0)return[];let i=[];for(let e of n){let{rect:n,viewport:a}=e;if(n.width<=0||n.height<=0)continue;let o=e.members?.length?[e.instanceId,...e.members]:[e.instanceId],s=[];for(let e of o){let n=r.isShown(e)?r.getLevels(e):[];n.length>0&&s.push(e=>this.renderLevels(e,n,a,t))}for(let e of o)s.push(t=>r.renderPanel(t,e,a));i.push({id:e.instanceId,rect:n,inner:{x:n.x,y:n.y+pe,width:n.width,height:n.height-pe},background:r=>{r.fillStyle=e.style?.background??t.style?.panes.background??t.background,r.fillRect(n.x,n.y,n.width,n.height)},steps:s})}return i}renderPanels(e,t,n,r){let{theme:i}=t,a=t.indicatorEngine;if(!a||n.length===0)return;let o=`10px ${i.font.family}`,s=this.panelDescriptors(a),c=new Map(t.panels.map(e=>[e.instanceId,e.style]));for(let a of n){let{rect:n,inner:l}=a,u=r.panes.get(a.id),d=c.get(a.id);e.save(),e.beginPath(),e.rect(n.x,n.y,n.width,n.height),e.clip(),u?.background||a.background(e),e.fillStyle=d?.separator??i.style?.panes.separator??i.axisLine,e.fillRect(n.x,n.y,n.width,3),e.fillStyle=i.style?.panes.title??i.textSecondary,e.font=o,e.textBaseline=`top`,e.textAlign=`left`;let f=s.get(a.id);f&&t.paneTitles!==!1&&e.fillText(f.descriptor.name,n.x+6,n.y+6),e.save(),e.beginPath(),e.rect(l.x,l.y,l.width,l.height),e.clip(),u?.text?.drawText(e);for(let t of u?u.rest:a.steps)t(e);e.restore(),e.restore()}}axisTagPlan(t){let{viewport:n,data:r}=t,{chartRect:i}=n,a=e=>e>=i.y&&e<=i.y+i.height,o=[],s=t.currentPriceLine?.isVisible()&&t.theme.style?.lastPrice.visible!==!1?t.currentPriceLine.getPrice():null;if(s!=null&&a(e.T(s,n))){let i=t.barCountdown?.isShown(r)?16:0;o.push({y:e.T(s,n),above:ge,below:ge+i,source:`last`,key:0})}for(let i of t.priceLines?.levels(r,n)??[]){let t=e.T(i.price,n);a(t)&&o.push({y:t,above:_e,below:_e,source:`quote`,key:i.kind})}(t.priceLimits?xe(t.priceLimits):[]).forEach(({price:t},r)=>{let i=e.T(t,n);a(i)&&o.push({y:i,above:he/2,below:he/2,source:`limit`,key:r})});let c=t.alignAxisLabels!==!1;c&&(t.tradingRenderer?.axisBadgeLines(n,t.theme)??[]).forEach((e,t)=>{o.push({y:e,above:16/2,below:16/2,source:`trading`,key:t})});let l=o.findIndex(e=>e.source===`last`),u={top:i.y,bottom:i.y+i.height},d=c?de(o,l>=0?l:null,u):o.map(e=>e.y),f={fixed:[],quote:new Map,limits:[],trading:c?[]:void 0};if(o.forEach((e,t)=>{Number.isNaN(d[t])||f.fixed.push({y:d[t]+(e.below-e.above)/2,half:(e.above+e.below)/2}),e.source===`quote`?f.quote.set(e.key,d[t]):e.source===`limit`?f.limits[e.key]=d[t]:e.source===`trading`&&(f.trading[e.key]=d[t])}),!c)for(let e of t.tradingRenderer?.axisTagYs(n,t.theme)??[])a(e)&&f.fixed.push({y:e,half:16/2});return f}overlayValueTags(n,r){let i=n.indicatorEngine?.getLatestOverlayValues();if(!i?.length)return[];let{viewport:a}=n,{chartRect:o}=a,s=n.numberLocale??`en-US`,c=(a.scaleMode===`percentage`||a.scaleMode===`indexedTo100`)&&a.scaleBaseline?e=>l(e,a,2,s):n.formatPrice??(e=>(0,t.formatPrice)(e,2,s));return ne(i.map(t=>({y:e.T(t.value,a),text:c(t.value),color:t.color})),{top:o.y,bottom:o.y+o.height},r)}renderLeftValueLabels(n,r,i){let a=r.indicatorEngine?.getLatestOverlayValues(`left`);if(!a?.length)return;let{chartRect:o}=i,s=r.leftAxisWidth??t.PRICE_AXIS_WIDTH,c=(0,t.autoPricePrecision)(i.priceRange.min,i.priceRange.max),l=r.numberLocale??`en-US`;ie(n,a.map(n=>({y:e.T(n.value,i),text:(0,t.formatPrice)(n.value,c,l),color:n.color})),o.x-s,s,{top:o.y,bottom:o.y+o.height},r.theme)}renderLevels(t,n,r,i){if(n.length===0)return;let{chartRect:a}=r;t.save(),t.strokeStyle=i.axisLabel,t.globalAlpha=.45,t.lineWidth=1,t.setLineDash([4,4]),t.beginPath();for(let i of n){let n=Math.round(e.T(i,r))+.5;t.moveTo(a.x,n),t.lineTo(a.x+a.width,n)}t.stroke(),t.restore()}renderPanelAxes(n,r){let{theme:i}=r,a=r.numberLocale??`en-US`,o=`${i.font.sizeSmall}px ${i.font.family}`;for(let s of r.panels){let c=s.viewport,u=s.rect,{min:d,max:f}=c.priceRange;if(f-d<=0||u.height<=0||c.chartRect.height<me)continue;let p=u.x+u.width,m=c.chartRect,h=i.style?.axis.price.line??i.axisLine,g=i.style?.axis.price.text??i.axisLabel;n.strokeStyle=h,n.lineWidth=1,n.beginPath(),n.moveTo(p+.5,u.y),n.lineTo(p+.5,u.y+u.height),n.stroke();let _=x(d,f,m.height),v=b(_);n.font=o,n.textBaseline=`middle`,n.textAlign=`left`;for(let t of S(d,f,_)){let r=e.T(t,c);r<m.y||r>m.y+m.height||(n.strokeStyle=h,n.beginPath(),n.moveTo(p,Math.round(r)+.5),n.lineTo(p+4,Math.round(r)+.5),n.stroke(),n.fillStyle=g,n.fillText(l(t,c,v,a),p+6,r))}let y=r.indicatorValueLabels===!1?null:[s.instanceId,...s.members??[]].flatMap(e=>r.indicatorEngine?.getLatestValues(e)??[]);y?.length&&ie(n,y.map(n=>({y:e.T(n.value,c),text:c.scaleMode===`percentage`&&c.scaleBaseline?l(n.value,c,2,a):(0,t.formatPrice)(n.value,k(n.value),a),color:n.color})),p,r.viewport.priceAxisWidth??t.PRICE_AXIS_WIDTH,{top:m.y,bottom:m.y+m.height},i)}}renderPanelCrosshair(n,r){let i=r.crosshairHandler?.getPosition();if(!i||r.panels.length===0||!r.crosshairHandler?.drawsLines())return;let{theme:a}=r;for(let o of r.panels){let s=o.rect;if(i.x<s.x||i.x>s.x+s.width||i.y<s.y||i.y>s.y+s.height)continue;let c=o.viewport;if(c.chartRect.height<me)continue;let l=e.A(i.x,c),u=e.b(Math.max(0,Math.min((r.data?.length??1)-1,Math.round(l))),c),d=ce(a);if(n.save(),n.beginPath(),n.rect(s.x,s.y,s.width,s.height),n.clip(),d.vertical.visible){n.setLineDash((0,t.lineDash)(d.vertical.style,[4,4],d.vertical.width)),n.strokeStyle=d.vertical.color;let r=e.g(n,u,d.vertical.width);n.lineWidth=r.width,n.beginPath(),n.moveTo(r.x,s.y),n.lineTo(r.x,s.y+s.height),n.stroke()}if(d.horizontal.visible){n.setLineDash((0,t.lineDash)(d.horizontal.style,[4,4],d.horizontal.width)),n.strokeStyle=d.horizontal.color;let r=e._(n,i.y,d.horizontal.width);n.lineWidth=r.width,n.beginPath(),n.moveTo(s.x,r.y),n.lineTo(s.x+s.width,r.y),n.stroke()}n.setLineDash([]),n.restore();break}}renderPanelHoverValues(n,r){let i=r.crosshairHandler?.getPosition(),a=r.indicatorEngine;if(!i||r.panels.length===0)return;let{theme:o,viewport:s,data:c}=r,u=r.numberLocale??`en-US`,d=`${o.font.sizeSmall}px ${o.font.family}`,f=a?this.panelDescriptors(a):null;for(let p of r.panels){let m=p.viewport,h=p.rect,{min:g,max:_}=m.priceRange;if(_-g<=0||h.height<=0||m.chartRect.height<me)continue;let v=h.x+h.width,y=b(x(g,_,m.chartRect.height));if(r.crosshairHandler?.getMode()!==`hidden`&&i.x>=h.x&&i.x<=h.x+h.width&&i.y>=h.y&&i.y<=h.y+h.height){let r=l(e.M(i.y,m),m,y,u);n.font=`bold ${o.font.sizeSmall}px ${o.font.family}`;let a=n.measureText(r).width,c=Math.min(a+De,(s.priceAxisWidth??t.PRICE_AXIS_WIDTH)-2),d=ce(o);n.fillStyle=d.labelBackground,O(n,v+1,i.y-Oe/2,c,Oe,o),n.fillStyle=d.labelText,n.textBaseline=`middle`,n.textAlign=`left`,n.fillText(r,v+5,i.y)}if(!a||r.paneTitles===!1||!a.isShown(p.instanceId))continue;let S=Math.max(0,Math.min((c?.length??1)-1,Math.round(e.A(i.x,m)))),C=a.peekOutput(p.instanceId),w=C?.series&&S<C.series.length?C.series[S]:null;if(!w)continue;let T=f?.get(p.instanceId),E=T?.descriptor.plots,D=[];if(E)for(let e of E){let t=w[e.key];t!==void 0&&Number.isFinite(t)&&D.push(`${e.title} ${l(t,m,y,u)}`)}else for(let e in w){let t=w[e];t!==void 0&&D.push(`${e}: ${t.toFixed(y)}`)}if(D.length===0)continue;n.font=d;let k=T?n.measureText(T.descriptor.name).width+14:10;n.fillStyle=o.textSecondary,n.textBaseline=`top`,n.textAlign=`left`,n.fillText(D.join(` `),h.x+k,h.y+6)}}panelDescriptors(e){let t=new Map;for(let n of e.getPanelIndicators())t.set(n.instanceId,n);return t}renderPriceLimits(n,r,i,a,o,s=[]){let{chartRect:c}=r,l=o??(e=>(0,t.priceTagText)(e,r,r.pricePrecision??ye)),u=`bold 9px ${i.font.family}`,d=`10px ${i.font.family}`;xe(a,i).forEach(({price:a,color:o,label:f},p)=>{let m=e.T(a,r);if(m<c.y||m>c.y+c.height)return;n.setLineDash([8,4]),n.strokeStyle=o,n.lineWidth=1,n.beginPath(),n.moveTo(c.x,Math.round(m)+.5),n.lineTo(c.x+c.width,Math.round(m)+.5),n.stroke(),n.setLineDash([]),n.font=u,n.fillStyle=o,n.textBaseline=`bottom`,n.textAlign=`left`,n.fillText(`${f} ${l(a)}`,c.x+4,m-2);let h=s[p]??m;if(Number.isNaN(h))return;let g=c.x+c.width+1;n.fillStyle=o,O(n,g,h-he/2,(r.priceAxisWidth??t.PRICE_AXIS_WIDTH)-2,he,i),n.fillStyle=i.background&&i.text?(0,t.inkOn)(o,i.background,i.text):ve,n.font=d,n.textBaseline=`middle`,n.textAlign=`left`,n.fillText(l(a),g+4,h)})}destroy(){this.renderLoop.stop(),this.detachGpu(),this.dprManager.destroy(),this.layerManager.destroy()}};function Ae(e){return{prices:e.priceAxis?.ticks(e.viewport),slots:e.timeAxis?.marks(e.viewport,e.data).map(e=>e.index)}}async function je(t){let n=e.n();if(!n)return{gpu:null,reason:`limit`};let r;try{r=await Promise.resolve().then(()=>require(`./WebGLSeriesRenderer-lwJz1WAg.cjs`))}catch(e){return n(),console.warn(`TradeCanvas: the WebGL renderer failed to load, drawing with Canvas 2D.`,e),{gpu:null,reason:`unsupported`}}let i=r.WebGLSeriesRenderer.create({failIfMajorPerformanceCaveat:t===`auto`,release:n});return i?{gpu:i}:(n(),{gpu:null,reason:`unsupported`})}async function Me(e){return(await je(e)).gpu}var Ne=.25,Pe=.02,Fe=1/t.PHI,Ie=t.PHI**4,Le=t.PHI**-5,Re=.2,ze=class{state;priceAxisWidth=t.PRICE_AXIS_WIDTH;stateCache=null;dataLength=0;margins={top:Le,bottom:Le};minBarWidth;maxBarWidth;rightMarginBars;freePan=!0;minVisibleBars=3;minBarUnit=Ne;barLayout=`classic`;constructor(e,n,r=2,i=30,a=5){this.minBarWidth=r,this.maxBarWidth=i,this.rightMarginBars=a;let o=this.computeChartRect(e,n);this.state={visibleRange:{from:0,to:0},priceRange:{min:0,max:1},barWidth:t.DEFAULT_BAR_WIDTH,barSpacing:t.DEFAULT_BAR_SPACING,offset:0,chartRect:o}}getState(){return this.stateCache||={visibleRange:{...this.state.visibleRange},priceRange:{...this.state.priceRange},barWidth:this.state.barWidth,barSpacing:this.state.barSpacing,offset:this.state.offset,chartRect:{...this.state.chartRect},logScale:this.state.logScale,scaleMode:this.state.scaleMode,scaleBaseline:this.state.scaleBaseline,invertScale:this.state.invertScale,priceAxisWidth:this.state.priceAxisWidth,formatPrice:this.state.formatPrice,numberLocale:this.state.numberLocale,pricePrecision:this.state.pricePrecision,priceUnit:this.state.priceUnit},this.stateCache}invalidate(){this.stateCache=null}setLogScale(e){this.setScaleMode(e?`logarithmic`:`regular`)}isLogScale(){return(this.state.scaleMode??(this.state.logScale?`logarithmic`:`regular`))===`logarithmic`}setScaleMode(e){this.state.scaleMode=e,this.state.logScale=e===`logarithmic`,this.invalidate()}getScaleMode(){return this.state.scaleMode??(this.state.logScale?`logarithmic`:`regular`)}setInvertScale(e){this.state.invertScale=e,this.invalidate()}isInvertScale(){return this.state.invertScale===!0}setNumberLocale(e){this.state.numberLocale=e,this.invalidate()}setPricePrecision(e){this.state.pricePrecision=e!==null&&Number.isInteger(e)&&e>=0?e:void 0,this.invalidate()}setPriceFormat(e,t=null){this.state.formatPrice=e??void 0,this.state.priceUnit=t??void 0,this.invalidate()}setScaleBaseline(e){this.state.scaleBaseline=e,this.invalidate()}setRightMargin(e){this.rightMarginBars=e}getRightMargin(){return this.rightMarginBars}setPanLimits(e){e.freePan!==void 0&&(this.freePan=e.freePan),e.minVisibleBars!==void 0&&(this.minVisibleBars=Math.max(1,Math.floor(e.minVisibleBars))),this.clampOffset(),this.updateVisibleRange()}endOffset(){let e=this.state.barWidth+this.state.barSpacing;return this.dataLength*e-this.state.chartRect.width+this.rightMarginBars*e}setPriceAxisWidth(e){this.priceAxisWidth!==e&&(this.priceAxisWidth=e,this.state.priceAxisWidth=e,this.invalidate())}computeChartRect(e,n){return{x:0,y:0,width:Math.max(0,e-this.priceAxisWidth),height:Math.max(0,n-t.TIME_AXIS_HEIGHT)}}resize(e,t){this.state.chartRect=this.computeChartRect(e,t),this.invalidate(),this.clampUnit(),this.clampOffset()}setChartRect(e){this.state.chartRect={x:e.x,y:e.y,width:Math.max(0,e.width),height:Math.max(0,e.height)},this.invalidate(),this.clampUnit(),this.clampOffset(),this.updateVisibleRange()}setBarLayout(e){let t=e===`golden`?`golden`:`classic`;if(t===this.barLayout)return;let n=this.dataLength>0&&this.isAtEnd();this.barLayout=t,this.applyUnit(this.dataLength===0?this.openingUnit():this.state.barWidth+this.state.barSpacing),this.clampUnit(),n&&(this.state.offset=this.endOffset(),this.invalidate()),this.clampOffset(),this.updateVisibleRange()}getBarLayout(){return this.barLayout}openingUnit(){return this.barLayout===`golden`?Ie:t.DEFAULT_BAR_WIDTH+t.DEFAULT_BAR_SPACING}floorUnit(){return this.barLayout===`golden`?this.minBarWidth/Fe:this.minBarWidth+t.DEFAULT_BAR_SPACING}minUnit(){let e=this.floorUnit(),t=this.state.chartRect.width,n=this.dataLength+this.rightMarginBars;return t<=0||n<=0?e:Math.max(this.minBarUnit,Math.min(e,t/n))}setMinBarUnit(e){this.minBarUnit=Number.isFinite(e)?Math.max(Pe,Math.min(e,this.floorUnit())):Ne,this.clampUnit(),this.clampOffset(),this.updateVisibleRange(),this.invalidate()}getMinBarUnit(){return this.minBarUnit}maxUnit(){return this.barLayout===`golden`?this.maxBarWidth/Fe:this.maxBarWidth+t.DEFAULT_BAR_SPACING}applyUnit(e){let n=this.floorUnit();if(this.barLayout===`golden`)this.state.barWidth=e*Fe,this.state.barSpacing=e-this.state.barWidth;else if(e>=n)this.state.barWidth=e-t.DEFAULT_BAR_SPACING,this.state.barSpacing=t.DEFAULT_BAR_SPACING;else{let t=this.minBarWidth/n;this.state.barWidth=e*t,this.state.barSpacing=e-this.state.barWidth}this.invalidate()}clampUnit(){let e=this.state.barWidth+this.state.barSpacing,n=(0,t.clamp)(e,this.minUnit(),this.maxUnit());n===e||e<=0||(this.state.offset=this.state.offset/e*n,this.applyUnit(n))}updateData(e,n){let r=this.dataLength===0;if(this.dataLength=e.length,this.dataLength!==0&&(this.clampUnit(),r&&(this.state.offset=this.endOffset()),this.clampOffset(),this.updateVisibleRange(),n)){let{min:n,max:r}=(0,t.computePriceRange)(e,this.state.visibleRange.from,Math.min(this.state.visibleRange.to,this.dataLength-1),0);this.fitToPrices(n,r)}}setScaleMargins(e){let t=e=>Number.isFinite(e)&&e>=0;!t(e.top)||!t(e.bottom)||1-e.top-e.bottom<Re||(this.margins={top:e.top,bottom:e.bottom})}getScaleMargins(){return{...this.margins}}fitToPrices(e,n){this.state.priceRange=(0,t.fitPriceRange)(e,n,this.margins,this.isLogScale()),this.invalidate()}prependBars(e){e===0||!Number.isFinite(e)||(this.dataLength+=e,this.state.offset+=e*(this.state.barWidth+this.state.barSpacing),this.invalidate(),this.updateVisibleRange())}setPriceRange(e,t){this.state.priceRange={min:e,max:t},this.invalidate()}scalePriceRange(e){if(!Number.isFinite(e)||e<=0)return;let{min:t,max:n}=this.state.priceRange,r=(t+n)/2,i=(n-t)/2,a=Math.max(i*e,1e-9);this.state.priceRange={min:r-a,max:r+a},this.invalidate()}scrollBy(e){this.state.offset+=e,this.invalidate(),this.clampOffset(),this.updateVisibleRange()}panPriceRange(e){let t=this.state.chartRect.height;if(t<=0||e===0)return;let{min:n,max:r}=this.state.priceRange,i=(this.state.invertScale?-e:e)/t;if(this.isLogScale()&&n>0&&r>0){let e=Math.log(n),t=Math.log(r),a=(t-e)*i;this.state.priceRange={min:Math.exp(e-a),max:Math.exp(t-a)},this.invalidate();return}let a=(r-n)*i;this.state.priceRange={min:n-a,max:r-a},this.invalidate()}isAtEnd(){let e=this.state.barWidth+this.state.barSpacing;return Math.abs(this.state.offset-this.endOffset())<=e*2}scrollToEnd(){this.state.offset=this.endOffset(),this.invalidate(),this.updateVisibleRange()}zoom(e,n){let r=this.state.barWidth+this.state.barSpacing,i=this.state.barWidth*(1+e),a=(0,t.clamp)(this.barLayout===`classic`&&r>=this.floorUnit()&&i>=this.minBarWidth?i+t.DEFAULT_BAR_SPACING:r*(1+e),this.minUnit(),this.maxUnit());if(a===r)return;let o=this.isAtEnd(),s=(this.state.offset+n)/r;this.applyUnit(a),this.state.offset=o?this.endOffset():s*a-n,this.invalidate(),this.clampOffset(),this.updateVisibleRange()}zoomToBarRange(e,n){let r=this.state.chartRect.width;if(r<=0||!Number.isFinite(e)||!Number.isFinite(n)||n<e)return;let i=(0,t.clamp)(r/(n-e+1),this.minUnit(),this.maxUnit());this.applyUnit(i),this.state.offset=(e+n+1)/2*i-r/2,this.invalidate(),this.clampOffset(),this.updateVisibleRange()}clampOffset(){if(this.state.chartRect.width<=0)return;let e=this.state.barWidth+this.state.barSpacing,n=this.state.chartRect.width,r=this.endOffset(),i,a;if(this.freePan&&this.dataLength>0){let t=Math.min(this.minVisibleBars,this.dataLength);i=t*e-n,a=(this.dataLength-t)*e,i=Math.min(i,r),a=Math.max(a,r)}else if(r>0)i=-(n*.5),a=r;else{let e=n*.5;i=r-e,a=r+e}this.state.offset=(0,t.clamp)(this.state.offset,i,a),this.invalidate()}updateVisibleRange(){let e=this.state.barWidth+this.state.barSpacing;if(e<=0||this.state.chartRect.width<=0)return;let t=Math.floor(this.state.offset/e),n=Math.ceil(this.state.chartRect.width/e)+1,r=Math.min(t+n,this.dataLength-1);this.state.visibleRange={from:Math.max(0,t),to:Math.max(0,r)},this.invalidate()}};function Be(e,n){return(0,t.sliceVisibleData)(e,n.visibleRange.from,n.visibleRange.to)}var Ve=[`1D`,`5D`,`1M`,`3M`,`6M`,`YTD`,`1Y`,`5Y`,`All`],He=864e5,Ue=6e4,We={"1M":1,"3M":3,"6M":6,"1Y":12,"5Y":60};function Ge(e,t){let n=new Date(e),r=n.getUTCFullYear(),i=n.getUTCMonth()+t,a=new Date(Date.UTC(r,i+1,0)).getUTCDate();return Date.UTC(r,i,Math.min(n.getUTCDate(),a),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds())}function Ke(e,n,r=0){if(e===`All`)return null;if(e===`1D`)return n-He;if(e===`5D`)return n-5*He;let i=n+(0,t.offsetAt)(r,n)*Ue;return e===`YTD`?(0,t.wallToUtc)(Date.UTC(new Date(i).getUTCFullYear(),0,1),r):(0,t.wallToUtc)(Ge(i,-(We[e]??0)),r)}function qe(e,t,n){if(t>=e){let t=Array(Math.max(0,e));for(let n=0;n<e;n++)t[n]=n;return t}if(t<=2)return e>=2?[0,e-1]:e===1?[0]:[];let r=[0],i=(e-2)/(t-2),a=0;for(let o=0;o<t-2;o++){let t=Math.floor((o+1)*i)+1,s=Math.floor((o+2)*i)+1;s>e&&(s=e);let c=0,l=0,u=0;for(let e=t;e<s;e++)c+=e,l+=n(e),u++;if(u>0)c/=u,l/=u;else{let r=Math.min(t,e-1);c=r,l=n(r)}let d=Math.floor(o*i)+1,f=Math.floor((o+1)*i)+1,p=n(a),m=-1,h=d;for(let e=d;e<f;e++){let t=Math.abs((a-c)*(n(e)-p)-(a-e)*(l-p));t>m&&(m=t,h=e)}r.push(h),a=h}return r.push(e-1),r}var Je=64;function Ye(e,t,n,r,i){let a=Math.max(0,e),o=Math.min(t,n-1);if(o<a)return[];let s=o-a+1,c=Math.max(Je,Math.ceil(r*2));if(s<=c){let e=Array(s);for(let t=0;t<s;t++)e[t]=a+t;return e}let l=qe(s,c,e=>i(a+e));for(let e=0;e<l.length;e++)l[e]+=a;return l}var Xe=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange;if(a>o||n.length===0)return;let s=r.barWidth+r.barSpacing,c=-r.offset+r.chartRect.x+r.barWidth/2,{min:l,max:u}=r.priceRange;if(u-l===0)return;let d=e.E(r);t.beginPath(),t.strokeStyle=i.lineColor,t.lineWidth=i.style?.series.lineWidth??2,t.lineJoin=`round`;let f=Ye(a,o,n.length,r.chartRect.width,e=>n[e].close),p=!1;for(let e of f){let r=e*s+c,i=d(n[e].close);p?t.lineTo(r,i):(t.moveTo(r,i),p=!0)}t.stroke()}},Ze=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange;if(a>o||n.length===0)return;let s=r.barWidth+r.barSpacing,c=-r.offset+r.chartRect.x+r.barWidth/2,{min:l,max:u}=r.priceRange;if(u-l===0)return;let d=e.E(r),f=d(l),p=Ye(a,o,n.length,r.chartRect.width,e=>n[e].close);if(p.length===0)return;let m=p[0],h=m*s+c,g=d(n[m].close),_=t.createLinearGradient(0,d(u),0,f);_.addColorStop(0,i.areaTopColor),_.addColorStop(1,i.areaBottomColor),t.beginPath(),t.moveTo(h,f),t.lineTo(h,g);let v=h;for(let e=1;e<p.length;e++){let r=p[e];v=r*s+c,t.lineTo(v,d(n[r].close))}t.lineTo(v,f),t.closePath(),t.fillStyle=_,t.fill(),t.beginPath(),t.strokeStyle=i.lineColor,t.lineWidth=i.style?.series.lineWidth??2,t.lineJoin=`round`,t.moveTo(h,g);for(let e=1;e<p.length;e++){let r=p[e];t.lineTo(r*s+c,d(n[r].close))}t.stroke()}},Qe=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange,s=r.barWidth,c=s+r.barSpacing,l=-r.offset+r.chartRect.x+s/2,{min:u,max:d}=r.priceRange;if(d-u===0)return;if(e.f(r)){e.p(t,n,r,i.candleUp,i.candleDown);return}let f=e.E(r);e.v(t,r=>{let{body:u,wick:d}=e.h(s,r.ratio),p=Math.max((u-d)/2,d),m=new Path2D,h=new Path2D;for(let e=a;e<=o&&e<n.length;e++){let t=n[e],i=t.close>=t.open?m:h,a=r.left(e*c+l,d),o=r.y(f(t.high)),s=r.y(f(t.low));i.rect(a,Math.min(o,s),d,Math.max(Math.abs(s-o),d)),i.rect(a-p,r.y(f(t.open))-Math.floor(d/2),p,d),i.rect(a+d,r.y(f(t.close))-Math.floor(d/2),p,d)}t.fillStyle=i.candleUp,t.fill(m),t.fillStyle=i.candleDown,t.fill(h)})}},$e=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange,s=r.barWidth,c=s+r.barSpacing,l=-r.offset+r.chartRect.x+s/2,{min:u,max:d}=r.priceRange;if(d-u===0)return;if(e.f(r)){e.p(t,n,r,i.candleUp,i.candleDown);return}let f=e.E(r);e.v(t,r=>{let{body:u,wick:d}=e.h(s,r.ratio),p=(u-d)/2,m={up:new Path2D,down:new Path2D},h={up:new Path2D,down:new Path2D},g={up:new Path2D,down:new Path2D};for(let e=a;e<=o&&e<n.length;e++){let t=n[e],i=e===0||t.close>=n[e-1].close?`up`:`down`,a=r.left(e*c+l,d),o=a-p,s=r.y(f(t.high)),_=r.y(f(t.low)),v=r.y(f(t.open)),y=r.y(f(t.close)),b=Math.min(v,y),x=Math.max(Math.abs(y-v),d);t.close>=t.open?(b>s&&m[i].rect(a,s,d,b-s),_>b+x&&m[i].rect(a,b+x,d,_-b-x),g[i].rect(o+d/2,b+d/2,Math.max(u-d,0),Math.max(x-d,0))):(m[i].rect(a,Math.min(s,_),d,Math.max(Math.abs(_-s),1)),h[i].rect(o,b,u,x))}for(let e of[`up`,`down`]){let n=e===`up`?i.candleUp:i.candleDown;t.fillStyle=n,t.fill(m[e]),t.fill(h[e]),t.strokeStyle=n,t.lineWidth=d,t.stroke(g[e])}})}},et=32/255,tt=class{baselinePrice=null;setBaseline(e){this.baselinePrice=e}render(t,n,r,i){let{from:a,to:o}=r.visibleRange;if(a>o||n.length===0)return;let s=r.barWidth,c=s/2,l=s+r.barSpacing,u=-r.offset+r.chartRect.x+c,{min:d,max:f}=r.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=e.E(r),h=m(this.baselinePrice??this.computeBaseline(n,a,o)),{chartRect:g}=r,_=[],v=[];for(let e=a;e<=o&&e<n.length;e++)_.push(p(e)),v.push(m(n[e].close));if(_.length<2)return;let y=_.length-1;t.save();let b=m(f),x=m(d),S=new Path2D;S.rect(g.x,Math.min(h,b),g.width,Math.abs(b-h)),t.clip(S);let C=new Path2D;C.moveTo(_[0],h);for(let e=0;e<=y;e++)C.lineTo(_[e],v[e]);C.lineTo(_[y],h),C.closePath(),t.globalAlpha*=et,t.fillStyle=i.candleUp,t.fill(C),t.restore(),t.save();let w=new Path2D;w.rect(g.x,Math.min(h,x),g.width,Math.abs(x-h)),t.clip(w);let T=new Path2D;T.moveTo(_[0],h);for(let e=0;e<=y;e++)T.lineTo(_[e],v[e]);T.lineTo(_[y],h),T.closePath(),t.globalAlpha*=et,t.fillStyle=i.candleDown,t.fill(T),t.restore();let E=new Path2D,D=new Path2D,O=null;for(let e=1;e<=y;e++){let t=r.invertScale?v[e]>=h:v[e]<=h,n=t?E:D;t!==O&&n.moveTo(_[e-1],v[e-1]),O=t,n.lineTo(_[e],v[e])}t.save(),t.lineWidth=i.style?.series.lineWidth??2,t.lineJoin=`round`,t.strokeStyle=i.candleUp,t.stroke(E),t.strokeStyle=i.candleDown,t.stroke(D),t.restore(),t.setLineDash([6,4]),t.strokeStyle=i.textSecondary,t.lineWidth=1;let k=new Path2D;k.moveTo(g.x,h),k.lineTo(g.x+g.width,h),t.stroke(k),t.setLineDash([])}computeBaseline(e,t,n){let r=0,i=0;for(let a=t;a<=n&&a<e.length;a++)r+=e[a].close,i++;return i>0?r/i:0}},nt=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange,s=r.barWidth,c=s/2,l=s+r.barSpacing,u=-r.offset+r.chartRect.x+c,{min:d,max:f}=r.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=e.E(r),h=new Path2D,g=new Path2D,_=new Path2D,v=new Path2D;for(let e=a;e<=o&&e<n.length;e++){let t=n[e],r=p(e),i=t.close>=t.open,a=m(Math.max(t.open,t.close)),o=m(Math.min(t.open,t.close)),l=Math.min(a,o),u=Math.max(Math.abs(o-a),1),d=r-c;i?(h.rect(d,l,s,u),_.rect(d,l,s,u)):(g.rect(d,l,s,u),v.rect(d,l,s,u))}t.fillStyle=i.candleUp,t.fill(h),t.fillStyle=i.candleDown,t.fill(g),t.lineWidth=1,t.strokeStyle=i.candleUp,t.stroke(_),t.strokeStyle=i.candleDown,t.stroke(v)}},rt=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange,s=r.barWidth,c=s/2,l=s+r.barSpacing,u=-r.offset+r.chartRect.x+c,{min:d,max:f}=r.priceRange;if(f-d===0)return;let p=e=>e*l+u,m=e.E(r),h=new Path2D,g=new Path2D;for(let e=a;e<=o&&e<n.length;e++){let t=n[e],r=p(e),i=t.close>=t.open,a=m(t.high),s=m(t.low),c=i?s:a,l=i?h:g;l.moveTo(r,i?a:s),l.lineTo(r,c),e<o&&e+1<n.length&&l.lineTo(p(e+1),c)}t.save(),t.lineJoin=`round`,t.strokeStyle=i.candleUp,t.lineWidth=3,t.stroke(h),t.strokeStyle=i.candleDown,t.lineWidth=1,t.stroke(g),t.restore()}},it=3,at=.8,ot=class{boxSize=1;setBoxSize(e){this.boxSize=e}render(t,n,r,i){let{from:a,to:o}=r.visibleRange,s=r.barWidth,c=s/2,l=s+r.barSpacing,u=-r.offset+r.chartRect.x+c,{min:d,max:f}=r.priceRange,p=f-d;if(p===0||!(this.boxSize>0))return;let m=r.chartRect.height/p,h=e=>e*l+u,g=e.E(r),_=Math.abs(this.boxSize*m);if(_<it){this.renderSolid(t,n,a,o,h,g,Math.max(1,s*at),i);return}let v=Math.min(c*at,_*at)*.5,y=new Path2D,b=new Path2D,x=new Path2D;for(let e=a;e<=o&&e<n.length;e++){let t=n[e],r=h(e),i=t.close>=t.open,a=t.high,o=t.low,s=Math.max(1,Math.round((a-o)/this.boxSize)),c=Math.max(0,Math.floor((d-o)/this.boxSize)-1),l=Math.min(s-1,Math.ceil((f-o)/this.boxSize));for(let e=c;e<=l;e++){let t=g(o+(e+.5)*this.boxSize);i?(y.moveTo(r-v,t-v),y.lineTo(r+v,t+v),b.moveTo(r+v,t-v),b.lineTo(r-v,t+v)):(x.moveTo(r+v,t),x.arc(r,t,v,0,Math.PI*2))}}t.lineWidth=1.5,t.strokeStyle=i.candleUp,t.stroke(y),t.stroke(b),t.strokeStyle=i.candleDown,t.stroke(x)}renderSolid(e,t,n,r,i,a,o,s){for(let c=Math.max(0,n);c<=r&&c<t.length;c++){let n=t[c],r=a(n.high),l=a(n.low);e.fillStyle=n.close>=n.open?s.candleUp:s.candleDown,e.fillRect(i(c)-o/2,Math.min(r,l),o,Math.max(1,Math.abs(l-r)))}}},st=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange,{min:s,max:c}=r.priceRange;if(c-s===0||a>o||n.length===0)return;if(e.f(r)){e.p(t,n,r,i.candleUp,i.candleDown);return}let l=r.barWidth+r.barSpacing,u=-r.offset+r.chartRect.x+r.barWidth/2,d=r.barWidth,f=0;for(let e=a;e<=o&&e<n.length;e++)n[e].volume>f&&(f=n[e].volume);f===0&&(f=1);let p=e=>e*l+u,m=e.E(r);e.v(t,r=>{let{wick:s}=e.h(d,r.ratio),c=new Path2D,l=new Path2D,u=new Path2D,h=new Path2D;for(let t=a;t<=o&&t<n.length;t++){let i=n[t],a=i.close>=i.open,o=r.left(p(t),s),g=r.y(m(i.high)),_=r.y(m(i.low));(a?c:l).rect(o,Math.min(g,_),s,Math.max(Math.abs(_-g),1));let{body:v}=e.h(d*Math.max(.2,i.volume/f),r.ratio),y=r.y(m(i.open)),b=r.y(m(i.close));(a?u:h).rect(o-(v-s)/2,Math.min(y,b),v,Math.max(Math.abs(b-y),s))}t.fillStyle=i.candleUpWick,t.fill(c),t.fillStyle=i.candleDownWick,t.fill(l),t.fillStyle=i.candleUp,t.fill(u),t.fillStyle=i.candleDown,t.fill(h)})}},ct=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange,{min:s,max:c}=r.priceRange;if(c-s===0||a>o||n.length===0)return;let l=r.barWidth+r.barSpacing,u=-r.offset+r.chartRect.x+r.barWidth/2,d=r.barWidth,f=0;for(let e=a;e<=o&&e<n.length;e++)n[e].volume>f&&(f=n[e].volume);f===0&&(f=1);let p=new Path2D,m=new Path2D,h=new Path2D,g=new Path2D,_=e=>e*l+u,v=e.E(r);for(let e=a;e<=o&&e<n.length;e++){let t=n[e],r=e>0?n[e-1]:t,i=_(e),a=v(t.high),o=v(t.low),s=t.close>=r.close,c=d*Math.max(.15,t.volume/f),l=c/2,u=Math.min(a,o),y=Math.max(Math.abs(o-a),1),b=s?p:m,x=s?h:g;b.rect(i-l,u,c,y),x.rect(i-l,u,c,y)}t.fillStyle=lt(i.candleUp,.55),t.fill(p),t.fillStyle=lt(i.candleDown,.55),t.fill(m),t.lineWidth=1,t.strokeStyle=i.candleUpWick,t.stroke(h),t.strokeStyle=i.candleDownWick,t.stroke(g)}};function lt(e,t){if(e.startsWith(`#`)){let n=Math.round(Math.max(0,Math.min(1,t))*255).toString(16).padStart(2,`0`);if(e.length===7)return`${e}${n}`;if(e.length===9)return`${e.slice(0,7)}${n}`}return e}var ut=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange;if(a>o||n.length===0)return;let{min:s,max:c}=r.priceRange;if(c-s===0)return;let l=r.barWidth+r.barSpacing,u=-r.offset+r.chartRect.x+r.barWidth/2,d=e=>e*l+u,f=e.E(r),p=[],m=[];for(let e=a;e<=o&&e<n.length;e++){let t=d(e);p.push({x:t,y:f(n[e].high)}),m.push({x:t,y:f(n[e].low)})}if(p.length===0)return;let h=t.createLinearGradient(0,f(c),0,f(s));h.addColorStop(0,i.areaTopColor),h.addColorStop(1,i.areaBottomColor),t.beginPath(),t.moveTo(p[0].x,p[0].y);for(let e=1;e<p.length;e++)t.lineTo(p[e].x,p[e].y);for(let e=m.length-1;e>=0;e--)t.lineTo(m[e].x,m[e].y);t.closePath(),t.fillStyle=h,t.fill(),t.beginPath(),t.strokeStyle=i.lineColor,t.lineWidth=i.style?.series.lineWidth??2,t.lineJoin=`round`;for(let e=a;e<=o&&e<n.length;e++){let r=d(e),i=f(n[e].close);e===a?t.moveTo(r,i):t.lineTo(r,i)}t.stroke()}},dt=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange;if(a>o||n.length===0)return;let{min:s,max:c}=r.priceRange;if(c-s===0)return;let l=r.barWidth+r.barSpacing,u=-r.offset+r.chartRect.x+r.barWidth/2,d=e=>e*l+u,f=e.E(r);t.beginPath(),t.strokeStyle=i.lineColor,t.lineWidth=i.style?.series.lineWidth??2,t.lineJoin=`miter`;let p=0;for(let e=a;e<=o&&e<n.length;e++){let r=d(e),i=f(n[e].close);e===a?t.moveTo(r,i):(t.lineTo(r,p),t.lineTo(r,i)),p=i}t.stroke()}},ft=class{render(t,n,r,i){let{from:a,to:o}=r.visibleRange;if(a>o||n.length===0)return;let{min:s,max:c}=r.priceRange;if(c-s===0)return;let l=r.barWidth+r.barSpacing,u=-r.offset+r.chartRect.x+r.barWidth/2,d=e=>e*l+u,f=e.E(r);t.beginPath(),t.strokeStyle=i.lineColor,t.lineWidth=i.style?.series.lineWidth??2,t.lineJoin=`round`;let p=[];for(let e=a;e<=o&&e<n.length;e++){let r=d(e),i=f(n[e].close);p.push({x:r,y:i}),e===a?t.moveTo(r,i):t.lineTo(r,i)}t.stroke();let m=Math.max(2,Math.min(4,r.barWidth*.3));if(l<m*2)return;let h=new Path2D;for(let{x:e,y:t}of p)h.moveTo(e+m,t),h.arc(e,t,m,0,Math.PI*2);t.fillStyle=i.lineColor,t.fill(h),t.strokeStyle=i.background,t.lineWidth=1,t.stroke(h)}},pt=28,mt=3,ht=class{priceText=null;setPriceText(e){this.priceText=e}render(n,r,i,a){let{from:o,to:s}=i.visibleRange,{min:c,max:l}=i.priceRange;if(l===c)return;if(e.f(i)){e.p(n,r,i,a.candleUp,a.candleDown);return}let u=i.barWidth+i.barSpacing,d=-i.offset+i.chartRect.x+i.barWidth/2,f=e.E(i),p=Math.max(1,Math.round(i.barWidth*.6)),m=i.barWidth>=pt,h=(0,t.autoPricePrecision)(c,l),g=e=>i.formatPrice?.(e)??this.priceText?.(e)??(0,t.formatPrice)(e,h);m&&(n.font=`${a.font.sizeSmall}px ${a.font.family}`,n.textAlign=`center`);for(let e=Math.max(0,o);e<=s&&e<r.length;e++){let t=r[e],i=e*u+d,o=Math.min(f(t.high),f(t.low)),s=Math.max(f(t.high),f(t.low));if(n.fillStyle=t.close>=t.open?a.candleUp:a.candleDown,n.fillRect(Math.round(i-p/2),o,p,Math.max(1,s-o)),!m)continue;let c=f(t.high)<=f(t.low);n.textBaseline=`bottom`,n.fillText(g(c?t.high:t.low),i,o-mt),n.textBaseline=`top`,n.fillText(g(c?t.low:t.high),i,s+mt)}}},gt=t.PHI**-4.5,_t=class{visible=!0;heightRatio=gt;setVisible(e){this.visible=e}isVisible(){return this.visible}setHeightRatio(e){this.heightRatio=Math.max(.05,Math.min(.5,e))}getHeightRatio(){return this.heightRatio}render(n,r,i,a){if(!this.visible||r.length===0)return;let{from:o,to:s}=i.visibleRange,{chartRect:c}=i,l=i.barWidth,u=l+i.barSpacing,d=-i.offset+c.x+l/2,f=0;for(let e=o;e<=s&&e<r.length;e++)r[e].volume>f&&(f=r[e].volume);if(f===0)return;let p=c.y+c.height,m=c.height*this.heightRatio/f;e.v(n,c=>{let f=new Path2D,h=new Path2D,g=c.y(p),_=(e,t,n,r)=>{let i=c.y(p-r*m);g-i>=1&&e.rect(t,i,n,g-i)};if(e.f(i))e.d(r,o,s,e=>e*u+d,e=>{let t=c.x(e.x);_(e.close>=e.open?f:h,t,Math.max(1,c.x(e.x+1)-t),e.volume)});else{let{body:t,wick:n}=e.h(l,c.ratio),i=(t-n)/2;for(let e=o;e<=s&&e<r.length;e++){let a=r[e];_(a.close>=a.open?f:h,c.left(e*u+d,n)-i,t,a.volume)}}let v=(0,t.resolveVolumeColors)(a);n.fillStyle=v.up,n.fill(f),n.fillStyle=v.down,n.fill(h)})}},vt=.32;function yt(e){return Number.isFinite(e)?vt*Math.min(1,Math.max(0,e)):vt}var bt=class{visible=!1;buckets=48;widthRatio=.18;opacity=vt;highlightPoC=!0;setVisible(e){this.visible=e}isVisible(){return this.visible}setBuckets(e){this.buckets=Math.max(8,Math.min(200,Math.floor(e)))}setWidthRatio(e){this.widthRatio=Math.max(.05,Math.min(.5,e))}setOpacity(e){this.opacity=Math.max(.05,Math.min(1,e))}setHighlightPoC(e){this.highlightPoC=e}render(t,n,r,i){if(!this.visible||n.length===0)return;let{from:a,to:o}=r.visibleRange,{chartRect:s,priceRange:c}=r,l=c.max-c.min;if(l<=0)return;let u=new Float64Array(this.buckets),d=new Float64Array(this.buckets),f=new Float64Array(this.buckets);for(let e=a;e<=o&&e<n.length;e++){let t=n[e];if(t.volume<=0)continue;let r=Math.max(t.low,c.min),i=Math.min(t.high,c.max);if(i<=r)continue;let a=(r-c.min)/l,o=(i-c.min)/l,s=Math.max(0,Math.floor(a*this.buckets)),p=Math.min(this.buckets-1,Math.floor(o*this.buckets)),m=Math.max(1,p-s+1),h=t.volume/m,g=t.close>=t.open;for(let e=s;e<=p;e++)u[e]+=h,g?d[e]+=h:f[e]+=h}let p=0,m=-1;for(let e=0;e<u.length;e++)u[e]>p&&(p=u[e],m=e);if(p===0)return;let h=s.width*this.widthRatio,g=s.x+s.width,_=e.E(r),v=1/p;t.save(),t.globalAlpha=this.opacity;for(let n=0;n<this.buckets;n++){let a=u[n];if(a===0)continue;let o=e.w(n,this.buckets,r,_),c=a*v*h,l=d[n]*v*h,p=f[n]*v*h;l>0&&(t.fillStyle=i.candleUp,t.fillRect(g-l,o.top+.5,l,o.height-1)),p>0&&(t.fillStyle=i.candleDown,t.fillRect(g-c,o.top+.5,p,o.height-1)),this.highlightPoC&&n===m&&(t.globalAlpha=1,t.strokeStyle=i.crosshair,t.lineWidth=1,t.setLineDash([3,2]),t.beginPath(),t.moveTo(s.x,o.mid+.5),t.lineTo(g-c-2,o.mid+.5),t.stroke(),t.setLineDash([]),t.globalAlpha=this.opacity)}t.restore()}},xt={session:`1d`,week:`1w`,month:`1M`},St=6e4,Ct=864e5,wt={},Tt=1.5;function Et(e){return e===`session`||e===`week`||e===`month`}function Dt(e,n,r){let i=Et(n)?xt[n]:n,a=(0,t.barTimeUnit)(e),o=r&&!(0,t.isUtcTimeZone)(r)&&(0,t.timeframeFollowsDays)(i)&&(0,t.isValidTimeZone)(r)?r:null,s=o===null?wt:{timeZone:o},c=o!==null&&(0,t.barsAreDaily)(e)===!0,l=(0,t.timeframeToMs)(i),u=(Number.isFinite(l)?l:St)*Tt,d=NaN,f=NaN,p=NaN,m=!1;return e=>{let n=e*a,r=c&&n%Ct===0;if(n>=d&&n<f&&r===m)return p;m=r;let l=r?wt:s;return d=(0,t.timeframeBucketStart)(n,i,l),f=(0,t.timeframeBucketStart)(d+u,i,l),p=o===null||r?d:(0,t.timeframeBucketStart)(n+(0,t.zoneOffsetMinutes)(o,n)*St,i),p}}function Ot(e,t,n){let r=e[t]?.[n];return e[t-1]?.[n]!==r&&e[t+1]?.[n]!==r}function kt(e,t,n,r=`session`){return e[t]?.[r]===e[n]?.[r]?!1:!(Ot(e,t,r)&&Ot(e,n,r))}function At(e,t){return e<0?0:e>t?t:e}function jt(e,t,n,r={}){let i=Math.max(4,Math.min(500,Math.floor(r.buckets??48))),a=n-t;if(a<=0||e.length===0)return null;let o=a/i,s=new Float64Array(i);for(let r of e){let e=Math.min(r.low,r.high),a=Math.max(r.low,r.high);if(a<t||e>n)continue;let c=At(Math.floor((e-t)/o),i-1),l=At(Math.floor((a-t)/o),i-1);for(let e=c;e<=l;e++)s[e]+=1}let c=0,l=0,u=0;for(let e=0;e<i;e++)u+=s[e],s[e]>l&&(l=s[e],c=e);if(u===0)return null;let d=u*(r.valueAreaPct??.7),f=c,p=c,m=s[c];for(;m<d&&(f>0||p<i-1);){let e=f>0?s[f-1]:-1;(p<i-1?s[p+1]:-1)>=e?(p+=1,m+=s[p]):(--f,m+=s[f])}let h=[];for(let e=0;e<i;e++){let n=t+e*o;h.push({low:n,high:n+o,mid:n+o/2,count:s[e]})}return{buckets:h,pocIndex:c,maxCount:l,totalCount:u,valueAreaLow:t+f*o,valueAreaHigh:t+(p+1)*o}}function Mt(e){let t=(e%52+52)%52;return t<26?String.fromCharCode(65+t):String.fromCharCode(97+t-26)}function Nt(e,t,n,r=48){let i=Math.max(4,Math.min(500,Math.floor(r))),a=n-t,o=Array.from({length:i},()=>[]);if(a<=0)return o;let s=a/i;return e.forEach((e,r)=>{let a=Math.min(e.low,e.high),c=Math.max(e.low,e.high);if(c<t||a>n)return;let l=Math.max(0,Math.min(i-1,Math.floor((a-t)/s))),u=Math.max(0,Math.min(i-1,Math.floor((c-t)/s)));for(let e=l;e<=u;e++)o[e].push(r)}),o}function Pt(e,t,n,r={},i){if(e.length===0||n-t<=0)return[];let a=[],o=Dt(e,`session`,i),s=0,c=o(e[0].time),l=(i,o,s)=>{let c=jt(e.slice(i,o+1),t,n,r);c&&a.push({startIndex:i,endIndex:o,startTime:s,profile:c})};for(let t=1;t<e.length;t++){let n=o(e[t].time);n!==c&&(l(s,t-1,c),s=t,c=n)}return l(s,e.length-1,c),a}var Ft=class{visible=!1;buckets=48;widthRatio=.18;opacity=.32;valueAreaPct=.7;highlightPoC=!0;showStats=!0;splitBySession=!1;letters=!1;lastStats=null;exchangeZone=null;setVisible(e){this.visible=e,e||(this.lastStats=null)}isVisible(){return this.visible}setBuckets(e){this.buckets=Math.max(8,Math.min(200,Math.floor(e)))}setWidthRatio(e){this.widthRatio=Math.max(.05,Math.min(.5,e))}setOpacity(e){this.opacity=Math.max(.05,Math.min(1,e))}setValueAreaPct(e){this.valueAreaPct=Math.max(.3,Math.min(.95,e))}setHighlightPoC(e){this.highlightPoC=e}setShowStats(e){this.showStats=e}setSplitBySession(e){this.splitBySession=e}isSplitBySession(){return this.splitBySession}getConfig(){let{buckets:e,widthRatio:t,opacity:n,valueAreaPct:r,highlightPoC:i,showStats:a,splitBySession:o,letters:s}=this;return{buckets:e,widthRatio:t,opacity:n,valueAreaPct:r,highlightPoC:i,showStats:a,splitBySession:o,letters:s}}setExchangeTimeZone(e){this.exchangeZone=e}setLetters(e){this.letters=e}drawsText(){return this.splitBySession?this.letters:this.showStats}getStats(){return this.lastStats}render(t,n,r,i){if(!this.visible||n.length===0)return;let{from:a,to:o}=r.visibleRange,{chartRect:s,priceRange:c}=r,l=Math.max(0,a),u=Math.min(o,n.length-1);if(u<l)return;let d=n.slice(l,u+1);if(this.splitBySession){this.lastStats=null,this.renderSplit(t,d,l,r,i);return}let f=jt(d,c.min,c.max,{buckets:this.buckets,valueAreaPct:this.valueAreaPct});if(!f){this.lastStats=null;return}let p=f.buckets[f.pocIndex].mid;this.lastStats={poc:p,vah:f.valueAreaHigh,val:f.valueAreaLow,valueAreaPct:this.valueAreaPct};let m=f.buckets.length,h=s.width*this.widthRatio,g=s.x,_=e.E(r),v=1/f.maxCount;t.save();for(let n=0;n<m;n++){let a=f.buckets[n];if(a.count===0)continue;let o=e.w(n,m,r,_),s=a.count*v*h,c=a.mid>=f.valueAreaLow&&a.mid<=f.valueAreaHigh;t.globalAlpha=c?Math.min(1,this.opacity+.18):this.opacity,t.fillStyle=c?i.candleUp:i.textSecondary,t.fillRect(g,o.top+.5,s,o.height-1)}t.globalAlpha=.6,t.strokeStyle=i.candleUp,t.lineWidth=1,t.setLineDash([1,3]);for(let e of[f.valueAreaHigh,f.valueAreaLow]){let n=_(e);t.beginPath(),t.moveTo(g,Math.round(n)+.5),t.lineTo(s.x+s.width,Math.round(n)+.5),t.stroke()}if(t.setLineDash([]),this.highlightPoC){let e=_(p);t.globalAlpha=1,t.strokeStyle=i.crosshair,t.lineWidth=1,t.setLineDash([3,2]),t.beginPath(),t.moveTo(g,Math.round(e)+.5),t.lineTo(s.x+s.width,Math.round(e)+.5),t.stroke(),t.setLineDash([])}this.showStats&&this.drawStats(t,s.x+6,s.y+6,p,f.valueAreaHigh,f.valueAreaLow,r,i),t.restore()}renderSplit(t,n,r,i,a){let{chartRect:o,priceRange:s}=i,c=Pt(n,s.min,s.max,{buckets:this.buckets,valueAreaPct:this.valueAreaPct},this.exchangeZone);if(c.length===0)return;let l=e.E(i),u=i.barWidth/2;t.save();for(let d of c){let c=d.profile,f=c.buckets.length,p=o.height/f,m=e.b(r+d.startIndex,i)-u,h=e.b(r+d.endIndex,i)+u,g=Math.max(2,h-m),_=1/c.maxCount,v=this.letters&&p>=7,y=v?Nt(n.slice(d.startIndex,d.endIndex+1),s.min,s.max,this.buckets):null;if(v&&y){t.font=`${Math.min(11,Math.floor(p))}px ui-monospace, monospace`,t.textBaseline=`middle`,t.textAlign=`left`;let n=Math.max(1,Math.floor(g/6));for(let r=0;r<f;r++){let o=y[r];if(o.length===0)continue;let s=e.w(r,f,i,l).mid,u=c.buckets[r].mid>=c.valueAreaLow&&c.buckets[r].mid<=c.valueAreaHigh;t.globalAlpha=u?.95:.6,t.fillStyle=u?a.candleUp:a.textSecondary;let d=Math.min(o.length,n);for(let e=0;e<d;e++)t.fillText(Mt(o[e]),m+e*6,s)}}else for(let n=0;n<f;n++){let r=c.buckets[n];if(r.count===0)continue;let o=e.w(n,f,i,l),s=r.count*_*g,u=r.mid>=c.valueAreaLow&&r.mid<=c.valueAreaHigh;t.globalAlpha=u?Math.min(1,this.opacity+.18):this.opacity,t.fillStyle=u?a.candleUp:a.textSecondary,t.fillRect(m,o.top+.5,s,o.height-1)}if(this.highlightPoC){let e=l(c.buckets[c.pocIndex].mid);t.globalAlpha=1,t.strokeStyle=a.crosshair,t.lineWidth=1,t.setLineDash([3,2]),t.beginPath(),t.moveTo(m,Math.round(e)+.5),t.lineTo(Math.min(h,o.x+o.width),Math.round(e)+.5),t.stroke(),t.setLineDash([])}}t.restore()}drawStats(e,n,r,i,a,o,s,c){let l=s.pricePrecision??It(i),u=e=>(0,t.priceTagText)(e,s,l),d=[[`POC`,u(i),c.text],[`VAH`,u(a),c.candleUp],[`VAL`,u(o),c.candleUp]];e.globalAlpha=1,e.font=`600 10px ${c.font.family}`,e.textBaseline=`middle`;let f=0;for(let[,t]of d)f=Math.max(f,e.measureText(t).width);let p=38+f,m=6+d.length*14;e.fillStyle=c.background,e.globalAlpha=.82,Lt(e,n,r,p,m,4),e.fill(),e.globalAlpha=1,d.forEach(([t,i,a],o)=>{let s=r+6/2+14/2+o*14;e.fillStyle=a,e.textAlign=`left`,e.fillText(t,n+6,s),e.fillStyle=c.text,e.textAlign=`right`,e.fillText(i,n+p-6,s)}),e.textAlign=`left`}};function It(e){let t=Math.abs(e);return t>=1e3?2:t>=1?4:6}function Lt(e,t,n,r,i,a){e.beginPath(),e.moveTo(t+a,n),e.arcTo(t+r,n,t+r,n+i,a),e.arcTo(t+r,n+i,t,n+i,a),e.arcTo(t,n+i,t,n,a),e.arcTo(t,n,t+r,n,a),e.closePath()}function Rt(e,t,n){let r=Dt(e,t===`day`?`session`:`week`,n),i=[];for(let t of e){let e=r(t.time),n=i[i.length-1];n&&n.key===e?(n.high=Math.max(n.high,t.high),n.low=Math.min(n.low,t.low),n.close=t.close):i.push({key:e,open:t.open,high:t.high,low:t.low,close:t.close})}return i}function zt(e,t=`day`,n){let r=Rt(e,t,n);if(r.length<2)return[];let i=r[r.length-2],a=r[r.length-1],o=t===`day`?`D`:`W`;return[{id:`p${o}h`,label:`P${o}H`,price:i.high},{id:`p${o}c`,label:`P${o}C`,price:i.close},{id:`p${o}l`,label:`P${o}L`,price:i.low},{id:`open`,label:t===`day`?`Day Open`:`Week Open`,price:a.open}]}var Bt=class{visible=!1;period=`day`;exchangeZone=null;setVisible(e){this.visible=e}isVisible(){return this.visible}setPeriod(e){this.period=e}getPeriod(){return this.period}setExchangeTimeZone(e){this.exchangeZone=e}render(t,n,r,i){if(!this.visible||n.length===0)return;let a=zt(n,this.period,this.exchangeZone);if(a.length===0)return;let{chartRect:o}=r,s=o.y,c=o.y+o.height;t.save(),t.font=`600 10px ${i.font.family}`,t.textBaseline=`middle`;for(let n of a){let a=e.T(n.price,r);if(a<s||a>c)continue;let l=Vt(n,i);t.strokeStyle=l,t.globalAlpha=.7,t.lineWidth=1,t.setLineDash([5,4]),t.beginPath(),t.moveTo(o.x,Math.round(a)+.5),t.lineTo(o.x+o.width,Math.round(a)+.5),t.stroke(),t.setLineDash([]),t.globalAlpha=1;let u=n.label,d=t.measureText(u).width,f=o.x+o.width-d-10;t.fillStyle=i.background,t.globalAlpha=.85,O(t,f-4,a-7,d+8,14,i),t.globalAlpha=1,t.fillStyle=l,t.textAlign=`left`,t.fillText(u,f,a+.5)}t.restore()}};function Vt(e,t){return e.id.endsWith(`h`)?t.candleUp:e.id.endsWith(`l`)?t.candleDown:t.textSecondary}function Ht(e){let t,n;return e.map(e=>{let r;return e.type===`high`?(r=t===void 0||e.price>t?`HH`:`LH`,t=e.price):(r=n===void 0||e.price<n?`LL`:`HL`,n=e.price),{...e,label:r}})}function Ut(e,t=5,n=5){let r=Math.max(1,Math.floor(t)),i=Math.max(1,Math.floor(n)),a=[];for(let t=r;t<e.length-i;t++){let n=e[t].high,o=e[t].low,s=!0,c=!0;for(let a=t-r;a<=t+i&&!(a!==t&&(e[a].high>=n&&(s=!1),e[a].low<=o&&(c=!1),!s&&!c));a++);s?a.push({index:t,price:n,type:`high`}):c&&a.push({index:t,price:o,type:`low`})}return a}var Wt=4,Gt=10,Kt=class{visible=!1;left=5;right=5;showLabels=!1;structureLabels=!1;setVisible(e){this.visible=e}isVisible(){return this.visible}setStrength(e,t){this.left=Math.max(1,Math.floor(e)),this.right=Math.max(1,Math.floor(t))}setShowLabels(e){this.showLabels=e}setStructureLabels(e){this.structureLabels=e}getConfig(){return{left:this.left,right:this.right,showLabels:this.showLabels,structureLabels:this.structureLabels}}render(t,n,r,i){if(!this.visible||n.length===0)return;let a=Ut(n,this.left,this.right);if(a.length===0)return;let o=this.structureLabels?Ht(a):a,{from:s,to:c}=r.visibleRange;t.save(),t.font=`10px ${i.font.family}`,t.textAlign=`center`;for(let n of o){if(n.index<s-1||n.index>c+1)continue;let a=e.b(n.index,r),o=e.T(n.price,r),l=n.type===`high`,u=l?i.candleDown:i.candleUp,d=l!==(r.invertScale===!0),f=d?o-8:o+8;t.fillStyle=u,t.beginPath(),d?(t.moveTo(a-5,f-5),t.lineTo(a+5,f-5),t.lineTo(a,f)):(t.moveTo(a-5,f+5),t.lineTo(a+5,f+5),t.lineTo(a,f)),t.closePath(),t.fill();let p=this.structureLabels&&`label`in n?String(n.label):this.showLabels?qt(n.price,r):null;p&&(t.textBaseline=d?`bottom`:`top`,t.fillText(p,a,d?f-5-1:f+5+1))}t.restore()}};function qt(e,n){return(0,t.priceTagText)(e,n,n.pricePrecision??Jt(e))}function Jt(e){let t=Math.abs(e);return t>=1?2:t===0?Wt-1:Math.min(Gt,Wt-1-Math.floor(Math.log10(t)))}function Yt(e){if(e.length<2)return 0;let t=e.map(e=>e.price).sort((e,t)=>e-t),n=[];for(let e=1;e<t.length;e++){let r=t[e]-t[e-1];r>0&&n.push(r)}return n.length===0?0:(n.sort((e,t)=>e-t),n[Math.floor(n.length/2)])}var Xt=class{buffer=[];constructor(e=240){this.capacity=e,this.capacity=Math.max(1,Math.floor(e))}push(e,t){let n={time:e,bids:t.bids.map(e=>({...e})),asks:t.asks.map(e=>({...e})),bidStep:Yt(t.bids),askStep:Yt(t.asks)},r=this.indexAfter(e);if(r>0&&this.buffer[r-1].time===e){this.buffer[r-1]=n;return}this.buffer.splice(r,0,n),this.buffer.length>this.capacity&&(this.buffer=this.buffer.slice(this.buffer.length-this.capacity))}indexAfter(e){let t=this.buffer;if(t.length===0||t[t.length-1].time<=e)return t.length;let n=0,r=t.length;for(;n<r;){let i=n+r>>1;t[i].time<=e?n=i+1:r=i}return n}snapshots(){return this.buffer}maxVolume(){let e=0;for(let t of this.buffer){for(let n of t.bids)n.volume>e&&(e=n.volume);for(let n of t.asks)n.volume>e&&(e=n.volume)}return e}getCapacity(){return this.capacity}setCapacity(e){this.capacity=Math.max(1,Math.floor(e)),this.buffer.length>this.capacity&&(this.buffer=this.buffer.slice(this.buffer.length-this.capacity))}clear(){this.buffer=[]}get size(){return this.buffer.length}},Zt=class{buffer=new Xt(240);visible=!1;opacity=.7;setVisible(e){this.visible=e}isVisible(){return this.visible}setOpacity(e){this.opacity=Math.max(.1,Math.min(1,e))}setCapacity(e){this.buffer.setCapacity(e)}getConfig(){return{opacity:this.opacity,capacity:this.buffer.getCapacity()}}push(e,t){this.buffer.push(e,t)}clear(){this.buffer.clear()}render(t,n,r){if(!this.visible)return;let i=this.buffer.snapshots();if(i.length===0)return;let a=this.buffer.maxVolume();if(a<=0)return;let o=1/a,{chartRect:s}=n,c=Math.max(2,n.barWidth+n.barSpacing),l=s.x,u=s.x+s.width,d=s.y,f=s.y+s.height;t.save();for(let a of i){let i=e.O(a.time,n);if(i<l-c||i>u+c)continue;let s=i-c/2;this.drawSide(t,a.bids,a.bidStep??Yt(a.bids),r.candleUp,s,c,n,o,d,f),this.drawSide(t,a.asks,a.askStep??Yt(a.asks),r.candleDown,s,c,n,o,d,f)}t.restore()}drawSide(t,n,r,i,a,o,s,c,l,u){if(n.length===0)return;let d=Qt(Math.min(n[0].price,n[n.length-1].price),r,s);t.fillStyle=i;for(let r of n){let n=e.T(r.price,s);n<l-d||n>u+d||(t.globalAlpha=Math.min(1,Math.sqrt(r.volume*c))*this.opacity,t.fillRect(a,n-d/2,o,d))}t.globalAlpha=1}};function Qt(t,n,r){if(!(n>0))return 3;let i=Math.abs(e.T(t,r)-e.T(t+n,r));return Math.max(2,Math.min(i,12))}var $t=class{series=new Map;set(e,n){if(!n||n.length===0){this.series.delete(e);return}let r=[...n].sort((e,t)=>e.time-t.time),i=(0,t.barTimeUnit)(r),a=r.map(e=>e.time*i),o=a[a.length-1],s=a.length>1?o-a[a.length-2]:0;this.series.set(e,{bars:r,times:a,end:o+s})}has(e){return this.series.has(e)}get(e){return this.series.get(e)?.bars}symbols(){return[...this.series.keys()]}closeAt(e,n,r){let i=this.series.get(e);if(!i)return;let a=(0,t.normalizeBarTime)(n,r),{times:o,bars:s}=i;if(a<o[0])return;let c=o.length-1;if(a>o[c]&&(i.end<=o[c]||a>=i.end))return;let l=0,u=c;for(;l<u;){let e=l+u+1>>1;o[e]<=a?l=e:u=e-1}return s[l].close}lastCloseAt(e,n,r){let i=this.closeAt(e,n,r);if(i!==void 0)return{close:i,stale:!1};let a=this.series.get(e);if(!(!a||(0,t.normalizeBarTime)(n,r)<a.times[0]))return{close:a.bars[a.bars.length-1].close,stale:!0}}},en=11,tn={mark:11,label:12,letter:13,text:14},nn={mark:0,label:1,letter:2,text:3},rn=12,an=.12,on=`#131416`,sn=`#1fa874`,cn=`#e8505b`,ln=`#e6e3dc`;function un(e){let n=e?.font,r=n?.sizeSmall??en,i=e=>Math.max(tn[e],r+nn[e]),a=e?.background??on;return{sizes:{mark:i(`mark`),label:i(`label`),letter:i(`letter`),text:i(`text`)},figures:n?.family||t.DEFAULT_FONT_FAMILY,prose:n?.textFamily||t.SANS_FONT_FAMILY,background:a,ink:e?.text??ln,handleFill:e?.style?.drawings?.handle??a,scale:Math.max(1,r/en),rise:e?.style?.trading?.profit??sn,fall:e?.style?.trading?.loss??cn}}var dn=un(null),fn=null,pn=!1;function mn(){pn=!0,fn=null}function hn(e,t,n,r){pn&&(fn=fn?{x0:Math.min(fn.x0,e),y0:Math.min(fn.y0,t),x1:Math.max(fn.x1,e+n),y1:Math.max(fn.y1,t+r)}:{x0:e,y0:t,x1:e+n,y1:t+r})}function gn(){pn=!1;let e=fn;return fn=null,e?{x:e.x0,y:e.y0,width:e.x1-e.x0,height:e.y1-e.y0}:null}var _n=null;function vn(e){_n=e}var yn=4;function bn(e,t,n,r){if(!_n)return{left:e,top:t};let i=_n.x+_n.width-yn-n,a=_n.y+_n.height-yn-r;return{left:Math.max(_n.x+yn,Math.min(e,i)),top:Math.max(_n.y+yn,Math.min(t,a))}}function xn(e){dn=un(e)}function M(){return dn}function N(e,t={}){return`${t.weight?`${t.weight} `:``}${dn.sizes[e]}px ${t.prose?dn.prose:dn.figures}`}function Sn(e,t=`text`){let n=e.fontSize;return n&&n!==rn?n:dn.sizes[t]}function Cn(e){return wn+Tn*Math.max(1,Number.isFinite(e)?e:1)}var wn=9,Tn=3,En=new Map,Dn=64,On=4.5;function kn(e){let n=`${e}|${dn.background}|${dn.ink}`,r=En.get(n);return r===void 0&&(En.size>=Dn&&En.clear(),r=(0,t.readableOn)(e,dn.background,dn.ink,On),En.set(n,r)),r}function An(e,t=dn.scale){return Math.min(Nn,jn+Mn*(Math.max(1,Number.isFinite(e)?e:1)-1))*t}var jn=4.5,Mn=.75,Nn=8;function Pn(e,t){let n=Math.max(1,t);switch(e){case`dashed`:return[Math.max(5,3*n),Math.max(4,2*n)];case`dotted`:return[0,Math.max(3,2.5*n)];case`guide`:return[3,3];default:return[]}}function P(e,n=an){return(0,t.ownFillColor)(e)??(0,t.withAlpha)(e.color,n)}function Fn(e){return(0,t.ownFillColor)(e)!==void 0}function In(e){return(0,t.inkOn)(e,`#0b0d10`,`#ffffff`)}var Ln=`rgba(12, 16, 22, 0.85)`,Rn=Ln;function zn(e){Rn=e?.background??Ln,xn(e)}function Bn(){return M().handleFill}function F(e,t,n,r,i=Rn){e.save(),e.lineJoin=`round`,e.lineWidth=Vn,e.strokeStyle=i,e.setLineDash([]),e.strokeText(t,n,r),e.restore(),e.fillText(t,n,r)}var Vn=4,Hn=()=>M().sizes.label,Un=4,Wn=3,Gn=[],Kn=[],qn=!1;function Jn(e){Gn=e??[],Kn=[],qn=e!==null}function Yn(e,t,n,r){qn&&Kn.push({x:e,y:t,width:n-e,height:r-t})}function Xn(e,t,n,r,i){return r>e.x&&t<e.x+e.width&&i>e.y&&n<e.y+e.height}function Zn(e,t,n,r){return Gn.some(i=>Xn(i,e,t,n,r))}function Qn(e,t,n,r){return Zn(e,t,n,r)||Kn.some(i=>Xn(i,e,t,n,r))}function $n(e,t,n){let r=n;for(let n of[...Gn,...Kn])t>n.x&&e<n.x+n.width&&(r=Math.max(r,n.y+n.height));return r}function er(e,t){let n=null;for(let r of[...Gn,...Kn])t>r.y&&e<r.y+r.height&&(n=Math.max(n??r.x+r.width,r.x+r.width));return n}var tr=()=>2*Hn();function nr(e,t,n,r,i=n,a=-1/0){e.font=N(`label`);let o=e.measureText(t).width,s=rr(n,i,r,o,a);e.textAlign=s.align,e.textBaseline=s.baseline,F(e,t,s.x,s.y),Yn(s.left,s.top,s.left+o,s.top+Hn())}function rr(e,t,n,r,i){let a=e+Un,o=t-Un-r,s=o>a?[a,o]:[a],c={top:n-Wn-Hn(),bottom:n-Wn},l={top:n+Wn,bottom:n+Wn+Hn()};for(let e of[c,l])if(!(e.top<i)){for(let t of s)if(!Qn(t,e.top,t+r,e.bottom)){let n=e===c;return{x:t,y:n?e.bottom:e.top,align:`left`,baseline:n?`bottom`:`top`,left:t,top:e.top}}}let u=s.map(e=>({l:e,top:$n(e,e+r,n)+Wn})),d=u.find(e=>e.top-n<=tr());if(d)return{x:d.l,y:d.top,align:`left`,baseline:`top`,left:d.l,top:d.top};let f=t-Un,p={left:f-r,top:n-Hn()/2};if(!Qn(p.left,p.top,f,p.top+Hn()))return{x:f,y:n,align:`right`,baseline:`middle`,...p};let m=u.reduce((e,t)=>t.top<e.top?t:e);return{x:m.l,y:m.top,align:`left`,baseline:`top`,left:m.l,top:m.top}}function ir(){return Math.round(M().sizes.label*ar)}var ar=1.5,or=4,sr=6;function cr(e,t){return Math.ceil(e.measureText(t).width)+2*sr}function lr(e,t,n,r,i,a=In(i)){let o=cr(e,t),s=ir(),c=Math.round(r-s/2);return hn(Math.round(n),c,o,s),e.fillStyle=i,e.beginPath(),typeof e.roundRect==`function`?e.roundRect(Math.round(n),c,o,s,or):e.rect(Math.round(n),c,o,s),e.fill(),e.fillStyle=a,e.textAlign=`left`,e.textBaseline=`middle`,e.fillText(t,Math.round(n)+sr,c+s/2+.5),o}var ur=1.35,dr=8,fr=5,pr=4,mr=.94,hr=.16,gr=6e4,_r=60*gr,vr=24*_r;function yr(e){let t=Math.abs(e);return t>=10||t===0?2:t>=1?4:Math.min(10,Math.ceil(-Math.log10(t))+3)}var br=2;function xr(e,n=e,r){return r?(0,t.priceTagText)(e,r,r.pricePrecision??yr(n)):e.toFixed(yr(n))}function Sr(e,n){return n?(0,t.formatPrice)(e,br,n.numberLocale??`en-US`):e.toFixed(br)}function Cr(e,t,n){let r=t-e,i=e===0?0:r/e*100,a=r>=0?`+`:``;return`${a}${xr(r,e,n)} (${a}${Sr(i,n)}%)`}function wr(e){let t=Math.abs(e);if(t<_r)return`${Math.round(t/gr)}m`;if(t<vr){let e=Math.floor(t/_r),n=Math.round((t-e*_r)/gr);return n>0?`${e}h ${n}m`:`${e}h`}let n=Math.floor(t/vr),r=Math.round((t-n*vr)/_r);if(n>=7){let e=Math.floor(n/7),t=n-e*7;return t>0?`${e}w ${t}d`:`${e}w`}return r>0?`${n}d ${r}h`:`${n}d`}function Tr(e){return!!e.data&&e.data.length>0}function Er(t,n,r,i){let a=e.D(t.anchors[n].time,i),o=e.D(t.anchors[r].time,i);return Math.round(Math.abs(o-a))}function Dr(e,t,n,r){return Tr(r)?wr(e.anchors[n].time-e.anchors[t].time):null}function Or(e,t,n,r,i=`center`,a=!0){let o=M();e.font=N(`label`);let s=Math.round(o.sizes.label*ur),c=0;for(let n of t)c=Math.max(c,e.measureText(n).width);let l=Math.ceil(c+dr*2),u=t.length*s+fr*2,d=bn(i===`left`?n:i===`right`?n-l:n-l/2,a?r-u:r,l,u),f=Math.round(d.left),p=Math.round(d.top);kr(e,f,p,l,u),e.fillStyle=o.ink,e.textAlign=`left`,e.textBaseline=`top`;for(let n=0;n<t.length;n++)e.fillText(t[n],f+dr,p+fr+n*s+(s-o.sizes.label)/2);return{x:f,y:p,width:l,height:u}}function kr(e,n,r,i,a){let o=M(),s=Math.round(n),c=Math.round(r),l=Math.round(i),u=Math.round(a);hn(s,c,l,u),e.beginPath(),typeof e.roundRect==`function`?e.roundRect(s+.5,c+.5,l-1,u-1,pr):e.rect(s+.5,c+.5,l-1,u-1),e.fillStyle=(0,t.withAlpha)(o.background,mr),e.fill(),e.strokeStyle=(0,t.withAlpha)(o.ink,hr),e.lineWidth=1,e.setLineDash([]),e.stroke()}function Ar(e,t){return e.find(e=>!Zn(e.left,e.top,e.right,e.bottom)&&t.every(t=>e.right<=t.left||t.right<=e.left||e.bottom<=t.top||t.bottom<=e.top))??null}function jr(e,t,n){let r=Math.abs(e.anchors[t[1]].price-e.anchors[t[0]].price),i=Math.abs(e.anchors[n[1]].price-e.anchors[n[0]].price);return i===0?`—`:(r/i).toFixed(3)}var Mr=4,Nr=10,Pr=3,Fr=14,Ir=8,Lr=2,Rr=3,zr=4,Br=2,Vr=(e,t)=>e.left<t.right&&t.left<e.right&&e.top<t.bottom&&t.top<e.bottom,Hr=class{symbols=new Map;mode=`percent`;store=new $t;aligned=new Map;reservedLevels=()=>[];setReservedLevels(e){this.reservedLevels=e}setMode(e){this.mode=e}getMode(){return this.mode}addSymbol(e){this.symbols.set(e.id,e),this.store.set(e.id,e.data),this.aligned.delete(e.id)}removeSymbol(e){this.symbols.delete(e),this.store.set(e,null),this.aligned.delete(e)}setSymbolData(e,t){let n=this.symbols.get(e);n&&(n.data=t,this.store.set(e,t),this.aligned.delete(e))}setSymbolVisible(e,t){let n=this.symbols.get(e);n&&(n.visible=t)}getSymbols(){return Array.from(this.symbols.values())}clear(){for(let e of this.symbols.keys())this.store.set(e,null);this.symbols.clear(),this.aligned.clear()}getPriceRange(e,t){let n=1/0,r=-1/0;for(let i of this.symbols.values()){if(!i.visible||i.data.length===0)continue;let a=this.line(i,e,t);if(a)for(let e=a.from;e<=a.to;e++){let t=a.priceAt(e);t!==null&&(t<n&&(n=t),t>r&&(r=t))}}return n<=r?{min:n,max:r}:null}render(e,t,n,r){if(this.symbols.size===0||t.length===0)return;let{chartRect:i}=n;e.save(),e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.clip();let a=[];for(let r of this.symbols.values()){if(!r.visible||r.data.length===0)continue;let i=this.renderSymbol(e,r,t,n);i&&a.push({sym:r,...i})}this.renderLabels(e,a,n,r),e.restore()}renderLabels(e,t,n,r){if(t.length===0)return;e.font=`bold ${Nr}px sans-serif`,e.textBaseline=`middle`,e.textAlign=`right`;let i=this.reservedBoxes(n);for(let a of t){let o=Ir+Rr+e.measureText(a.sym.label).width+2*Pr,s=this.placeLabel(a,o,i,t,n.chartRect);i.push(s),this.drawLabel(e,a.sym,s,r)}}drawLabel(e,t,n,r){let i=(n.top+n.bottom)/2,a=n.left+Pr;e.strokeStyle=t.color,e.lineWidth=Lr,e.beginPath(),e.moveTo(a,i),e.lineTo(a+Ir,i),e.stroke(),e.fillStyle=r.text,F(e,t.label,n.right-Pr,i,r.background)}placeLabel(e,t,n,r,i){let a=e.x-Mr,o=e=>({left:a-t,top:e,right:a,bottom:e+Fr}),s=e.y-Mr-Fr,c=e.y+Mr,l=Array.from({length:zr},(e,t)=>[o(s-t*Fr),o(c+t*Fr)]).flat(),u=i.y+i.height,d=e=>e.top>=i.y&&e.bottom<=u&&!n.some(t=>Vr(t,e)),f=t=>{let n=(t.top+t.bottom)/2,i=t=>Math.hypot(t.x-e.x,t.y-n);return r.every(t=>t===e||i(t)>i(e))};return l.find(e=>d(e)&&f(e))??l.find(d)??o(Math.max(i.y,Math.min(s,u-Fr)))}reservedBoxes(t){let{chartRect:n}=t;return this.reservedLevels().map(r=>{let i=e.T(r,t)-Br;return{left:n.x,top:i-Fr,right:n.x+n.width,bottom:i}})}closesOn(e,n){let r=n.length>0?n[n.length-1].time:NaN,i=this.aligned.get(e.id);if(i&&i.main===n&&i.data===e.data&&i.length===n.length&&i.lastTime===r)return i.closes;let a=new Float64Array(n.length),o=(0,t.barTimeUnit)(n);for(let t=0;t<n.length;t++)a[t]=this.store.closeAt(e.id,n[t].time,o)??NaN;return this.aligned.set(e.id,{main:n,data:e.data,length:n.length,lastTime:r,closes:a}),a}anchor(e,t,n){let r=this.closesOn(e,t),i=Math.max(0,n.visibleRange.from),a=Math.min(t.length-1,n.visibleRange.to),o=-1;for(let e=i;e<=a;e++)if(Number.isFinite(r[e])&&r[e]!==0&&t[e].close!==0){o=e;break}if(o<0)return null;let s=n.scaleBaseline||t[i]?.close||t[o].close;return{closes:r,base:o,to:a,mainBase:s,symBase:r[o]}}line(e,t,n){let r=this.anchor(e,t,n);if(!r)return null;let{closes:i,mainBase:a,symBase:o}=r,s=this.mode===`percent`;return{from:r.base,to:r.to,priceAt:e=>{let t=i[e];return Number.isFinite(t)?s?t/o*a:t:null}}}valuesAt(e,n,r){let i=e[r]?.time,a=(0,t.barTimeUnit)(e);return this.getSymbols().map(t=>{let r=i===void 0?void 0:this.store.lastCloseAt(t.id,i,a),o=r&&n?this.anchor(t,e,n)?.symBase:void 0,s=r?.close??null;return{id:t.id,label:t.label,color:t.color,visible:t.visible,close:s,change:s!==null&&o?(s/o-1)*100:null,stale:r?.stale??!1}})}renderSymbol(t,n,r,i){let a=this.line(n,r,i);if(!a)return null;t.strokeStyle=n.color,t.lineWidth=n.lineWidth??1.5,t.lineJoin=`round`,t.beginPath();let o=0,s=null;for(let n=a.from;n<=a.to;n++){let r=a.priceAt(n);if(r===null)continue;let c=e.b(n,i),l=e.T(r,i);o===0?t.moveTo(c,l):t.lineTo(c,l),s={x:c,y:l},o++}return t.stroke(),s}};function Ur(e){if(e.length===0)return[];let t=[],n=e[0].open,r=(e[0].open+e[0].high+e[0].low+e[0].close)/4;for(let i=0;i<e.length;i++){let a=e[i],o=(a.open+a.high+a.low+a.close)/4,s=i===0?a.open:(n+r)/2,c=Math.max(a.high,s,o),l=Math.min(a.low,s,o);t.push({time:a.time,open:s,high:c,low:l,close:o,volume:a.volume}),n=s,r=o}return t}var Wr=1e5,Gr=[1,2,5],Kr=15;function qr(e,t){if(t===0)return e;let n=Gr[t%Gr.length],r=Math.floor(t/Gr.length),i=n*10**r;if(Number.isFinite(i))return Number((e*i).toPrecision(Kr));let[a,o]=e.toExponential().split(`e`);return Number(`${(Number(a)*n).toPrecision(Kr)}e${Number(o)+r}`)}function Jr(e,t,n){return e===t-1?n+Wr:Wr}var Yr=class{reached=null;clear(){this.reached=null}startStep(e,t,n){let r=this.reached;if(!r||r.kind!==e||r.asked!==t||n.length<r.length||n[0].time!==r.first)return 0;let i=n[r.length-1];return i.high>=r.high&&i.low<=r.low?r.step:0}keep(e,t,n,r){let i=r[r.length-1];this.reached=i?{kind:e,asked:t,step:n,first:r[0].time,length:r.length,high:i.high,low:i.low}:null}};function Xr(e,t,n,r,i){let a=i(e?.startStep(t,n,r)??0);return e?.keep(t,n,a.step,r),a}function Zr(e,t,n=0){return $r(e,t,()=>({bars:[],size:1/0,step:0}),n)}function Qr(e,t,n=0){return $r(e,t,()=>({bars:ei(e,t,!1)??[],size:e,step:0}),n)}function $r(e,t,n,r){let i=qr(e,r),a=ei(i,t,!0);if(a)return{bars:a,size:i,step:r};let o=ti(e,e=>t(e,!0),r),s=Number.isFinite(o)?qr(e,o):1/0,c=Number.isFinite(s)?ei(s,t,!0):null;return c?{bars:c,size:s,step:o}:n()}function ei(e,t,n){let r=[];return t(e,n,e=>{r.push(e)})?r:null}function ti(e,t,n){if(!(e>0))return 1/0;let r=n=>{let r=qr(e,n);return r===1/0||t(r)};if(r(n+1))return n+1;if(!t(Number.MAX_VALUE))return 1/0;let i=n+1,a=n+2;for(;!r(a);)i=a,a=n+2*(a-n);for(;a-i>1;){let e=Math.floor((i+a)/2);r(e)?a=e:i=e}return a}var ni=new WeakMap,ri=new WeakMap;function ii(e,t){return ni.set(e,t),e}function ai(e){let t=e[e.length-1];if(!t||!ni.has(t))return e;let n=ri.get(e);if(!n){let t=ni.get(e[0])??e[0].time;n=e.map(e=>(t=ni.get(e)??t,{time:t})),ri.set(e,n)}return n}function oi(e,t,n){if(e.length===0)return[];let r=si(e,t),i=(t,n,r)=>ci(e,t,n,r);return Xr(n,`renko`,r,e,e=>Zr(r,i,e)).bars}function si(e,t){let n=t.useATR&&e.length>2?ui(e,t.atrPeriod??14):t.brickSize;return n>0?n:Math.abs(e[e.length-1].close)/100||1}function ci(e,t,n,r){let i=e.findIndex(e=>Number.isFinite(e.close));if(i<0)return!0;let a=e[0].time,o=Math.round(e[i].close/t)*t,s=0;for(let c=i+1;c<e.length;c++){let{close:i,volume:l}=e[c],u=i-o,d=Math.floor(Math.abs(u)/t);if(!Number.isFinite(i)||!(d>=1))continue;if(n&&s+d>Jr(c,e.length,s))return!1;let f=u>0?1:-1;for(let n=0;n<d;n++){let i=o;o+=f*t,r?.(ii(li(a+s+n,i,o,l/d),e[c].time))}s+=d}return!0}function li(e,t,n,r){return{time:e,open:t,high:Math.max(t,n),low:Math.min(t,n),close:n,volume:r}}function ui(e,t){let n=e.length-1,r=Math.max(1,n-t),i=0;for(let t=r;t<n;t++)i+=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));let a=n>r?i/(n-r):0;if(!(a>0))return 0;let o=10**(Math.floor(Math.log10(a))-1);return Math.round(a/o)*o}function di(e,t=3){if(e.length===0)return[];let n=[],r=0;n.push(ii({time:r++,open:e[0].open,high:Math.max(e[0].open,e[0].close),low:Math.min(e[0].open,e[0].close),close:e[0].close,volume:e[0].volume},e[0].time));for(let i=1;i<e.length;i++){let a=e[i].close,o=n[n.length-1],s=o.close>=o.open,c=Math.min(t,n.length),l=-1/0,u=1/0;for(let e=n.length-c;e<n.length;e++)l=Math.max(l,n[e].high),u=Math.min(u,n[e].low);s&&a>o.close?n.push(ii({time:r++,open:o.close,high:a,low:o.close,close:a,volume:e[i].volume},e[i].time)):!s&&a<o.close||s&&a<u?n.push(ii({time:r++,open:o.close,high:o.close,low:a,close:a,volume:e[i].volume},e[i].time)):!s&&a>l&&n.push(ii({time:r++,open:o.close,high:a,low:o.close,close:a,volume:e[i].volume},e[i].time))}return n}function fi(e,t=4,n=`percent`,r){if(e.length<2)return e.slice();let i=(t,r,i)=>pi(e,t,n,r,i);return Xr(r,`kagi:${n}`,t,e,e=>Qr(t,i,e)).bars}function pi(e,t,n,r,i){let a=e[1].close>=e[0].close?1:-1,o=e[0].close,s=e[0].close,c=e[0].close,l=0;for(let u=1;u<e.length;u++){let d=e[u].close,f=n===`price`?t:t/100*c;if(a===1&&d>o&&(o=d),a===-1&&d<s&&(s=d),a===1?o-d>=f:d-s>=f){if(r&&l+1>Jr(u,e.length,l))return!1;i?.(ii(mi(l,c,a===1?o:s,e[u].volume),e[u].time)),l++,c=a===1?o:s,a=-a,o=d,s=d}}return i?.(ii(mi(l,c,a===1?o:s,0),e[e.length-1].time)),!0}function mi(e,t,n,r){return{time:e,open:t,high:Math.max(t,n),low:Math.min(t,n),close:n,volume:r}}function hi(e,t,n=3,r){return gi(e,t,n,r).columns}function gi(e,t,n=3,r){if(e.length===0||!(t>0))return{columns:[],boxSize:t};let i=(t,r,i)=>_i(e,t,n,r,i),{bars:a,size:o}=Xr(r,`pointAndFigure:${n}`,t,e,e=>Qr(t,i,e));return{columns:a,boxSize:o}}function _i(e,t,n,r,i){let a=1,o=0,s=e[0].close,c=Math.round(s/t)*t;if(vi(s,c))return!1;let l=c,u=c,d=e[0].volume,f=t*n;for(let n=1;n<e.length;n++){let s=e[n].close,c=Math.round(s/t)*t;if(vi(s,c))return!1;let p=!1;if(a===1?c>l?l=c:p=l-c>=f:c<u?u=c:p=c-u>=f,!p){d+=e[n].volume;continue}if(r&&o+1>Jr(n,e.length,o))return!1;i?.(ii(yi(o,a===1,u,l,d),e[n].time)),d=e[n].volume,o++,a===1?(u=c,l-=t):(l=c,u+=t),a=-a}return i?.(ii(yi(o,a===1,u,l,d),e[e.length-1].time)),!0}function vi(e,t){return Number.isFinite(e)&&!Number.isFinite(t)}function yi(e,t,n,r,i){return{time:e,open:t?n:r,high:r,low:n,close:t?r:n,volume:i}}var bi=15,xi=`rangeBars`,Si=3,Ci=4,wi=64,Ti=2;function Ei(e){let t=0;for(let n of e){let e=Math.abs(n.high),r=Math.abs(n.low);e>t&&e!==1/0&&(t=e),r>t&&r!==1/0&&(t=r)}return t}function Di(e,t){let n=Math.max(e,t),r=Math.floor(Math.log10(n))+1,i=Number.isFinite(n)?bi-r:0,a=10**-i;if(i<=0)return{clean:e=>e,unit:a,half:0};let o=10**i;return{clean:e=>Math.round(e*o)/o,unit:a,half:a/2}}function Oi(e,t){let n=-1/0,r=1/0;for(let i of[t,e.open,e.high,e.low,e.close])Number.isFinite(i)&&(n=Math.max(n,i),r=Math.min(r,i));return n>r?n-r:0}function ki(e){let t=0,n=e[0].open;for(let r=0;r<e.length-1;r++)t+=Oi(e[r],n),n=e[r].close;return{distance:t,bars:e.length-1,lastSpan:Oi(e[e.length-1],n)}}function Ai(e,t,n){if(t<Ti*n)return!1;let r=t+n,i=(e.distance-e.bars*n)/r-e.bars,a=(e.lastSpan-n)/r-1;return Math.max(i,a)>Wr+1}function ji(e){let t=new Float64Array(e.length*2);return t.set(e),t}function Mi(e,t,n,r){let i=r/(n-t);for(let r=t;r<n;r++)e[r*Ci+2]+=i}function Ni(e,t,n,r){let i=Array(t);for(let a=0;a<t;a++){let t=e[a*Ci],o=e[a*Ci+1],s=t>o;i[a]=ii({time:r+a,open:n,high:s?t:o,low:s?o:t,close:t,volume:e[a*Ci+2]},e[a*Ci+3]),n=t}return i}function Pi(e,t,n,r){let{clean:i,unit:a,half:o}=n,s=0,c=e[0].open,l=c,u=c,d=c,f=0,p=i(c+t),m=i(c-t);for(let n=0;n<e.length;n++){let h=Jr(n,e.length,s),g=e[n],_=g.close>=g.open,v=g.volume/Si;for(let e=0;e<=Si;e++){let n=e===0?g.open:e===1?_?g.low:g.high:e===2?_?g.high:g.low:g.close;if(!Number.isFinite(n))continue;d=n;let y=s;for(;;){let e=n>l&&n>=p-o&&p>u;if(!e&&!(n<u&&n<=m+o&&m<l))break;let d=e?p:m;if(e?d<l-a:d>u+a)return{cells:r,count:s,forming:null};let _=s*Ci;if(_===r.length&&(r=ji(r)),r[_]=d,r[_+1]=e?u:l,r[_+2]=f,r[_+3]=g.time,++s>h)return{cells:r,count:s,forming:null};c=l=u=d,p=i(d+t),m=i(d-t),f=0}n>l&&(l=n,m=i(n-t)),n<u&&(u=n,p=i(n+t));let b=e===0?0:v;s===y?f+=b:Mi(r,y,s,b)}}let h={time:e[0].time+s,open:c,high:l,low:u,close:d,volume:f};return{cells:r,count:s,forming:ii(h,e[e.length-1].time)}}function Fi(e,t,n){if(e.length===0||!(t.rangeSize>0))return[];let r=Ei(e),i=new Float64Array(Ci*Math.max(wi,Math.min(e.length,Wr))),a=null,o=n?.startStep(xi,t.rangeSize,e)??0;for(let s=o;;s++){let c=qr(t.rangeSize,s),l=Di(r,c);if(s>o&&(a??=ki(e),Ai(a,c,l.unit)))continue;let u=Pi(e,c<l.half?1/0:c,l,i);if(i=u.cells,!u.forming)continue;let d=Ni(i,u.count,e[0].open,e[0].time),{forming:f}=u;return t.includeForming&&(d.length===0||f.high-f.low>l.half)&&d.push(f),n?.keep(xi,t.rangeSize,s,e),d}}function Ii(e){return e.barWidth+e.barSpacing<1}function Li(e,t,n){return e>1.5*(Math.abs(n-t)+1)}var Ri=3,zi=class{started=!1;piece=0;lastX=NaN;lastY=NaN;col=NaN;lo=0;hi=0;width;constructor(e,t,n,r,i=[]){this.ctx=e,this.dense=r,this.dash=i,this.width=Number.isFinite(n)&&n>0?n:1,e.beginPath(),r?e.fillStyle=t:(e.strokeStyle=t,e.lineWidth=this.width,e.lineJoin=`round`)}add(e,t){!Number.isFinite(e)||!Number.isFinite(t)||(this.dense?this.addDense(e,t):this.started?this.ctx.lineTo(e,t):this.ctx.moveTo(e,t),this.started=!0,this.piece++,this.lastX=e,this.lastY=t)}gap(){this.endPiece(),this.flush(),this.started=!1,this.lastY=NaN}segment(e,t,n,r){(!this.started||e!==this.lastX||t!==this.lastY)&&(this.gap(),this.add(e,t)),this.add(n,r)}finish(){this.endPiece(),this.flush(),this.dense?this.ctx.fill():this.dash.length>0?(this.ctx.setLineDash([...this.dash]),this.ctx.stroke(),this.ctx.setLineDash([])):this.ctx.stroke()}endPiece(){if(!this.dense&&this.piece===1){let e=Math.max(this.width,Ri);this.ctx.moveTo(this.lastX-e,this.lastY),this.ctx.lineTo(this.lastX+e,this.lastY)}this.piece=0}addDense(e,t){let n=Math.floor(e);n!==this.col&&(this.flush(),this.col=n,this.lo=this.hi=Number.isNaN(this.lastY)?t:this.lastY),t<this.lo&&(this.lo=t),t>this.hi&&(this.hi=t)}flush(){if(Number.isNaN(this.col))return;let e=this.width/2,t=Math.max(1,this.width);this.ctx.rect(this.col+.5-t/2,this.lo-e,t,this.hi-this.lo+2*e),this.col=NaN}};function Bi(e,t,n,r,i,a=t.length){e.beginPath(),e.fillStyle=i;let o=NaN,s=0,c=0,l=NaN,u=NaN,d=()=>{Number.isNaN(o)||e.rect(o,s,1,c-s)};for(let e=0;e<a;e++){let i=Math.floor(t[e]),a=Math.min(n[e],r[e]),f=Math.max(n[e],r[e]);i!==o&&(d(),o=i,s=Number.isNaN(l)?a:Math.min(a,l),c=Number.isNaN(u)?f:Math.max(f,u)),a<s&&(s=a),f>c&&(c=f),l=a,u=f}d(),e.fill()}var Vi=.1;function Hi(e){return e.plots?e.plots.map(e=>e.key):null}function Ui(e,t){return e.tone?e.tone===`sign`?(t[e.key]??0)>=0:t[e.tone.field]===1:!0}function Wi(e,t){return t.plots?.[e.key]?.visible!==!1}var Gi=[6,4];function Ki(e,n,r){let i=e.plots?.[n];return{visible:i?.visible!==!1,dash:(0,t.lineDash)(i?.lineStyle??`solid`,Gi,r)}}function qi(e,t,n){let r=t.colors[e.color]??t.colors[0];return!e.tone||e.downColor===void 0||!n||Ui(e,n)?r:t.colors[e.downColor]??r}function Ji(e,t,n,r){let{lo:i,hi:a}=Xi(e,t,n,r.keys),o=r.scale,s=o?.min,c=o?.max;if(i===1/0){if(s===void 0&&c===void 0)return null;i=s??0,a=c??i+1}else{let e=a-i||Math.abs(a)||1;i-=e*Vi,a+=e*Vi}for(let e of r.levels??[])e<i&&(i=e),e>a&&(a=e);return(r.zero||o?.zero)&&(i>0&&(i=0),a<0&&(a=0)),s!==void 0&&(i=s),c!==void 0&&(a=c),a>i||(a=i+1),{min:i,max:a}}function Yi(e,t,n,r){let{lo:i,hi:a}=Xi(e,t,n,r.keys),o=e=>e!==void 0&&e>0,s=o(r.scale?.min)?r.scale?.min:void 0,c=o(r.scale?.max)?r.scale?.max:void 0;if(i===1/0){if(s===void 0||c===void 0)return null;i=s,a=c}else{if(!(i>0))return!1;let e=Math.exp((Math.log(a/i)||Math.LN2/4)*Vi);i/=e,a*=e}for(let e of r.levels??[])e>0&&(e<i&&(i=e),e>a&&(a=e));return s!==void 0&&(i=s),c!==void 0&&(a=c),a>i?{min:i,max:a}:null}function Xi(e,t,n,r){let i=1/0,a=-1/0,o=e=>{e===void 0||!Number.isFinite(e)||(e<i&&(i=e),e>a&&(a=e))},s=e=>{if(e){if(r){for(let t=0;t<r.length;t++)o(e[r[t]]);return}for(let t in e)o(e[t])}},c=e?.series;if(c){let e=Math.min(n,c.length-1);for(let n=Math.max(0,t);n<=e;n++)s(c[n])}else if(e){let r=0;for(let i of e.values.values()){if(r>n)break;r>=t&&s(i),r++}}return{lo:i,hi:a}}function Zi(e){return!!e?.some(e=>e.kind===`histogram`)}function Qi(n,r,i,a,o,s=[]){let c=r.series;if(!c)return;let l=Math.max(0,i.visibleRange.from),u=Math.min(i.visibleRange.to,c.length-1);if(u<l)return;let d=e.E(i);for(let e of s){let r=(0,t.withAlpha)(a.colors[e.color]??a.colors[0],e.opacity??$i);ea(n,c,e.between,l,u,i,d,r)}for(let e=0;e<o.length;e++){let r=o[e];if(!Wi(r,a))continue;let s=(e>0?a.lineWidths[e]:void 0)??r.width??a.lineWidths[0]??1.5,f=(0,t.lineDash)(a.plots?.[r.key]?.lineStyle??r.lineStyle??`solid`,Gi,s),p=r.kind??`line`,m=r.breakOn,h=m===void 0?null:(e,t)=>kt(c,e,t,m),g=n.globalAlpha;r.opacity!==void 0&&(n.globalAlpha=g*r.opacity);let _=r.tone&&r.downColor!==void 0?[!0,!1]:[null];try{for(let e of _){let t=a.colors[r.color]??a.colors[0],o=e===!1?a.colors[r.downColor]??t:t,m=t=>e===null||Ui(r,t)===e;p===`histogram`?aa(n,c,r.key,l,u,i,d,o,m):p===`dots`?ia(n,c,r.key,l,u,i,d,o,m):ra(n,c,r.key,l,u,i,d,o,s,p===`step`,e===null?null:m,f,h)}}finally{n.globalAlpha=g}}}var $i=.1;function ea(t,n,r,i,a,o,s,c){let l=a-i+1,u=new Float64Array(l),d=new Float64Array(l),f=new Float64Array(l),p=Ii(o),m=0,h=()=>{m>=2&&(p?Bi(t,u,d,f,c,m):ta(t,u,d,f,c,m)),m=0};for(let t=i;t<=a;t++){let i=na(n[t],r[0]),a=na(n[t],r[1]);if(i===void 0||a===void 0){h();continue}u[m]=e.b(t,o),d[m]=s(i),f[m]=s(a),m++}h()}function ta(e,t,n,r,i,a){e.beginPath(),e.moveTo(t[0],n[0]);for(let r=1;r<a;r++)e.lineTo(t[r],n[r]);for(let n=a-1;n>=0;n--)e.lineTo(t[n],r[n]);e.closePath(),e.fillStyle=i,e.fill()}function na(e,t){let n=e?.[t];return n!==void 0&&Number.isFinite(n)?n:void 0}function ra(t,n,r,i,a,o,s,c,l,u,d,f=[],p=null){let m=new zi(t,c,l,Ii(o),f),h=0,g=0,_=!1,v=-1;for(let t=i;t<=a;t++){let i=n[t],a=na(i,r);if(a===void 0){_=!1,m.gap();continue}_&&p?.(v,t)&&(_=!1,m.gap()),v=t;let c=e.b(t,o),l=s(a);d?_&&d(i)&&(u?(m.segment(h,g,c,g),m.add(c,l)):m.segment(h,g,c,l)):(_&&u&&m.add(c,g),m.add(c,l)),h=c,g=l,_=!0}m.finish()}function ia(t,n,r,i,a,o,s,c,l){let u=Math.max(1.5,o.barWidth*.15),d=Ii(o),f=NaN;t.beginPath(),t.fillStyle=c;for(let c=i;c<=a;c++){let i=n[c],a=na(i,r);if(a===void 0||!l(i))continue;let p=e.b(c,o);if(d){let e=Math.floor(p);if(e===f)continue;f=e}let m=s(a);t.moveTo(p+u,m),t.arc(p,m,u,0,Math.PI*2)}t.fill()}function aa(t,n,r,i,a,o,s,c,l){let u=s(0);if(t.beginPath(),t.fillStyle=c,Ii(o)){let c=NaN,d=0,f=()=>{if(Number.isNaN(c))return;let e=s(d);t.rect(c,Math.min(e,u),1,Math.max(1,Math.abs(e-u)))};for(let t=i;t<=a;t++){let i=n[t],a=na(i,r);if(a===void 0||!l(i))continue;let s=Math.floor(e.b(t,o));s===c?Math.abs(a)>Math.abs(d)&&(d=a):(f(),c=s,d=a)}f(),t.fill();return}let d=Math.max(1,o.barWidth);for(let c=i;c<=a;c++){let i=n[c],a=na(i,r);if(a===void 0||!l(i))continue;let f=e.b(c,o),p=s(a);t.rect(f-d/2,Math.min(p,u),d,Math.max(1,Math.abs(p-u)))}t.fill()}var I=class{canResume(e,t,n){let r=t.series;if(!r||n<=0||n>r.length||r.length>e.length)return!1;for(let i=n;i<r.length;i++)if(r[i]&&!t.values.has(e[i].time))return!1;return!0}writePoint(e,t,n,r){e.series[n]=r,r?e.values.set(t[n].time,r):e.values.delete(t[n].time)}render(e,t,n,r){this.descriptor.plots&&Qi(e,t,n,r,this.descriptor.plots,this.descriptor.fills)}drawLine(e,t,n,r,i){if(t.length<2||i?.visible===!1)return;let a=new zi(e,n,r,Li(t.length,t[0].x,t[t.length-1].x),i?.dash);for(let e of t)a.add(e.x,e.y);a.finish()}drawBand(e,t,n,r){if(!(t.length<2||n.length<2)){if(t.length===n.length&&Li(t.length,t[0].x,t[t.length-1].x)){Bi(e,t.map(e=>e.x),t.map(e=>e.y),n.map(e=>e.y),r);return}e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n++)e.lineTo(t[n].x,t[n].y);for(let t=n.length-1;t>=0;t--)e.lineTo(n[t].x,n[t].y);e.closePath(),e.fillStyle=r,e.fill()}}drawHistogram(e,t,n){let r=n/2;for(let i of t){e.fillStyle=i.color;let t=Math.min(i.y,i.baseY),a=Math.abs(i.y-i.baseY);e.fillRect(i.x-r,t,n,Math.max(a,1))}}valuesToPoints(t,n,r,i){let a=[],{from:o,to:s}=i.visibleRange;for(let c=o;c<=s&&c<r.length;c++){let o=t.values.get(r[c].time);o&&o[n]!==void 0&&a.push({x:e.b(c,i),y:e.T(o[n],i)})}return a}};function oa(e){return e.config.visible!==!1&&!e.offInterval&&!e.offChartType}function sa(e){let t=Hi(e.plugin.descriptor),n=e.style.plots;return t&&n?t.filter(e=>n[e]?.visible!==!1):t}function ca(e,t){return e.plugin.descriptor.placement!==`overlay`||e.config.pane?!1:e.config.scale===`left`==(t===`left`)}function la(e){let t=e.output?.series,n=e.plugin.descriptor.plots;if(!t||!n||!oa(e))return[];let r=t[t.length-1];if(!r)return[];let i=[];for(let t of n){if(!Wi(t,e.style))continue;let n=r[t.key];n!==void 0&&Number.isFinite(n)&&i.push({value:n,color:qi(t,e.style,r)})}return i}function ua(e,t){let n=[];for(let r of e)ca(r,t)&&n.push(...la(r));return n}function da(e,t,n,r){let i=null;for(let a of e){if(!oa(a))continue;let e=a.plugin.descriptor,o={keys:sa(a),scale:e.scale,levels:a.config.levels??e.levels,zero:Zi(e.plots)},s=r?Yi(a.output,t,n,o):Ji(a.output,t,n,o);if(s===!1)return null;s&&(i=i?{min:Math.min(i.min,s.min),max:Math.max(i.max,s.max)}:s)}return i}function fa(e,t){let n=[];for(let r of e){if(!oa(r))continue;let e=r.output?.series?.[t];if(!e)continue;let i=sa(r)??Object.keys(e);for(let t of i){let r=e[t];typeof r==`number`&&Number.isFinite(r)&&n.push(r)}}return n}function pa(e,t,n){if(n){for(let r=0;r<n.length;r++){let i=t[n[r]];i!==void 0&&isFinite(i)&&(i<e.min&&(e.min=i),i>e.max&&(e.max=i))}return}for(let n in t){let r=t[n];r!==void 0&&isFinite(r)&&(r<e.min&&(e.min=r),r>e.max&&(e.max=r))}}function ma(e,t,n,r){let i=t.output?.series;if(!i)return;let a=sa(t),o=Math.min(r,i.length-1),s=r>=i.length-1?t.output?.meta?.ahead:void 0,c=Array.isArray(s)?s:[];for(let t=Math.max(0,n);t<=o+c.length;t++){let n=t<=o?i[t]:c[t-o-1];n&&pa(e,n,a)}}function ha(e,t,n,r){let i={min:1/0,max:-1/0};for(let a of e)!a.output||!oa(a)||!ca(a,r)||ma(i,a,t,n);return i.min===1/0?null:i}function ga(e,t,n,r){let i=new Set;for(let a of e)a.config.instanceId!==r&&(n===null?t===`overlay`&&a.plugin.descriptor.placement===`overlay`&&!a.config.pane:a.config.instanceId===n||a.config.pane===n)&&i.add(a.style.colors[0]);return i}function _a(e,n,r,i,a){let o=ga(e,r,i,a);for(let t of e)t.config.id===n&&t.config.instanceId!==a&&o.add(t.style.colors[0]);let s=t.TC_SERIES_COLORS.findIndex(e=>!o.has(e));return s>=0?s:o.size%t.TC_SERIES_COLORS.length}function va(e){let t=e.inputs;if(!t)return null;for(let e in t)if(t[e]?.source)return e;return null}function ya(e,n){let r=va(e);if(!r)return{kind:`bars`};let i=n[r],a=(0,t.parseIndicatorSource)(i);return a?{kind:`line`,...a}:(0,t.isPriceSource)(i)&&i!==`close`?{kind:`price`,source:i}:{kind:`bars`}}function ba(e,n,r=null,i=0){let a=r&&i>0&&i<=r.length?r:[],o=a===r?i:0;a.length=e.length;for(let r=o;r<e.length;r++){let i=e[r];a[r]={...i,close:(0,t.sourcePrice)(i,n)}}return a}function xa(e,t,n){if(!t)return null;let r=-1;for(let i=0;i<e.length&&i<t.length;i++){let e=t[i]?.[n];if(e!==void 0&&Number.isFinite(e)){r=i;break}}if(r<0)return null;let i=Array(e.length-r),a=t[r][n];for(let o=r;o<e.length;o++){let s=t[o]?.[n];s!==void 0&&Number.isFinite(s)&&(a=s);let c=e[o];i[o-r]={time:c.time,open:a,high:a,low:a,close:a,volume:c.volume}}return{bars:i,start:r}}function Sa(e,t,n){if(t===0||!e.series)return e;let r=Array(n).fill(null);for(let i=0;i<e.series.length&&t+i<n;i++)r[t+i]=e.series[i];return{...e,series:r}}function Ca(e){return{values:new Map,series:Array(e).fill(null)}}var wa=[`ticks`,`seconds`,`minutes`,`hours`,`days`,`weeks`,`months`],Ta={ticks:1e6,seconds:59,minutes:59,hours:24,days:366,weeks:52,months:12},Ea={s:`seconds`,m:`minutes`,h:`hours`,d:`days`,w:`weeks`,M:`months`};function Da(e){let n=(0,t.tickBarCount)(e);if(n!==null)return{unit:`ticks`,count:n};let r=(0,t.parseTimeframe)(e);return r?{unit:Ea[r.unit],count:r.count}:null}function Oa(e,t){if(!e||!t)return!0;let n=Da(t);if(!n)return!0;let r=e[n.unit];return r===void 0?!0:r===!1?!1:n.count>=r[0]&&(n.count<=r[1]||r[1]>=Ta[n.unit])}function ka(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let t=e,n={};for(let e of wa){let r=t[e];if(r===!1){n[e]=!1;continue}if(!Array.isArray(r)||r.length!==2||!r.every(e=>typeof e==`number`&&Number.isFinite(e)))continue;let i=Ta[e],[a,o]=r.map(e=>Math.min(i,Math.max(1,Math.round(e)))).sort((e,t)=>e-t);(a>1||o<i)&&(n[e]=[a,o])}return Object.keys(n).length>0?n:null}function Aa(e){return[...t.TC_SERIES_COLORS.slice(e),...t.TC_SERIES_COLORS.slice(0,e)]}function ja(e){let n=t.TC_SERIES_COLORS.length;if(e.length!==n)return!1;let r=t.TC_SERIES_COLORS.indexOf(e[0]);return r>=0&&e.every((e,i)=>e===t.TC_SERIES_COLORS[(r+i)%n])}function Ma(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,{...t}]))}function Na(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t===!1?!1:[t[0],t[1]]]))}var Pa=new WeakSet,L=class e extends Map{keyBuf=[];valBuf=[];folded=!1;constructor(){super()}static fromAscending(t,n){let r=new e;for(let e=1;e<t.length;e++)if(!(t[e]>t[e-1])){for(let e=0;e<t.length;e++)r.set(t[e],n[e]);return r}return r.keyBuf=t,r.valBuf=n,r}set(e,t){if(this.folded)return super.set(e,t);let n=this.keyBuf,r=n.length;if(r===0||e>n[r-1])return n.push(e),this.valBuf.push(t),this;let i=this.indexOf(e);return i>=0?(this.valBuf[i]=t,this):(this.fold(),super.set(e,t))}get(e){if(this.folded)return super.get(e);let t=this.indexOf(e);return t>=0?this.valBuf[t]:void 0}has(e){return this.folded?super.has(e):this.indexOf(e)>=0}delete(e){if(this.folded)return super.delete(e);let t=this.indexOf(e);return t<0?!1:(this.keyBuf.splice(t,1),this.valBuf.splice(t,1),!0)}clear(){super.clear(),this.keyBuf=[],this.valBuf=[],this.folded=!1}get size(){return this.folded?super.size:this.keyBuf.length}forEach(e,t){this.fold(),super.forEach(e,t)}entries(){return this.fold(),super.entries()}keys(){return this.fold(),super.keys()}values(){return this.fold(),super.values()}[Symbol.iterator](){return this.fold(),super[Symbol.iterator]()}indexOf(e){let t=this.keyBuf,n=0,r=t.length-1;for(;n<=r;){let i=n+r>>1,a=t[i];if(a===e)return i;a<e?n=i+1:r=i-1}return-1}fold(){if(this.folded)return;this.folded=!0;let e=this.keyBuf,t=this.valBuf;for(let n=0;n<e.length;n++)super.set(e[n],t[n]);this.keyBuf=[],this.valBuf=[]}};function R(e,t){let n=new L;for(let r=0;r<t.length;r++){let i=t[r];i&&n.set(e[r].time,i)}return{values:n,series:t}}function Fa(e){return e.map(e=>e.close)}function Ia(e,t){let n=Array(e.length).fill(void 0),r=0,i=0;for(let a=0;a<e.length;a++){let o=e[a];if(o===void 0){r=0,i=0;continue}r+=o,i++,i>t&&(r-=e[a-t]),i>=t&&(n[a]=r/t)}return n}function La(e,t,n){let r=Array(e.length).fill(void 0),i=0,a=0,o;for(let s=0;s<e.length;s++){let c=e[s];if(c!==void 0){if(o===void 0){i+=c,a++,a===t&&(r[s]=o=i/t);continue}o+=n*(c-o),r[s]=o}}return r}function z(e,t){return La(e,t,2/(t+1))}function Ra(e,t){let n=Array(e.length).fill(void 0),r=t*(t+1)/2;for(let i=t-1;i<e.length;i++){let a=0,o=!0;for(let n=0;n<t;n++){let r=e[i-t+1+n];if(r===void 0){o=!1;break}a+=r*(n+1)}o&&(n[i]=a/r)}return n}function za(e,t){return La(e,t,1/t)}function Ba(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=0,o=!0;for(let n=r-t+1;n<=r;n++){let t=e[n];if(t===void 0){o=!1;break}i+=t,a+=t*t}if(!o)continue;let s=i/t;n[r]=Math.sqrt(Math.max(0,a/t-s*s))}return n}function Va(e){return e.map((t,n)=>{if(n===0)return t.high-t.low;let r=e[n-1].close;return Math.max(t.high-t.low,Math.abs(t.high-r),Math.abs(t.low-r))})}function Ha(e,t,n){if(t<n-1)return;let r=-1/0;for(let i=t-n+1;i<=t;i++){let t=e[i];if(t===void 0)return;t>r&&(r=t)}return r}function Ua(e,t,n){if(t<n-1)return;let r=1/0;for(let i=t-n+1;i<=t;i++){let t=e[i];if(t===void 0)return;t<r&&(r=t)}return r}function Wa(e,t=`value`){return e.map(e=>e!==void 0&&Number.isFinite(e)?{[t]:e}:null)}function Ga(e,t,n){if(t<n-1||t>=e.length)return;let r=0,i=0;for(let a=t-n+1;a<=t;a++){let t=e[a].close;r+=t,i+=t*t}let a=r/n;return{mean:a,sd:Math.sqrt(Math.max(0,i/n-a*a))}}function Ka(e,t,n){if(t<n-1)return;let r=-1/0;for(let i=t-n+1;i<=t;i++)e[i].high>r&&(r=e[i].high);return r}function qa(e,t,n){if(t<n-1)return;let r=1/0;for(let i=t-n+1;i<=t;i++)e[i].low<r&&(r=e[i].low);return r}function Ja(e,t,n){if(t<n-1)return;let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i].close;return r/n}function Ya(e,t,n){if(n<2||t<n-1)return;let r=n,i=(r-1)/2,a=0;for(let n=0;n<r;n++)a+=e[t-r+1+n].close;a/=r;let o=0,s=0,c=0;for(let n=0;n<r;n++){let l=n-i,u=e[t-r+1+n].close-a;o+=l*u,s+=l*l,c+=u*u}let l=o/s,u=a-l*i,d=0;for(let n=0;n<r;n++){let i=e[t-r+1+n].close-(u+l*n);d+=i*i}return{slope:l,end:u+l*(r-1),stdErr:r>2?Math.sqrt(d/(r-2)):0,r:c===0?0:o/Math.sqrt(s*c)}}var Xa=new WeakMap;function Za(e){let t=Xa.get(e);return t||Xa.set(e,t=Array.from(e)),t}var B=class extends I{times=new WeakMap;workerState(){}adoptWorkerState(e,t,n){this.times.set(e,Za(n))}lookback(e){return 0}revisesBefore(e){return this.lookback(this.read(e))}calculate(e,t){let n=this.read(t),r=Array(e.length);for(let t=0;t<e.length;t++)r[t]=this.pointAt(e,t,n);let i=R(e,r);return this.times.set(i,e.map(e=>e.time)),i}update(e,t,n,r){let i=this.times.get(n);if(!i||!this.canResume(e,n,r))return null;for(let t=r;t<i.length&&t<e.length;t++)if(i[t]!==e[t].time)return null;let a=this.read(t);for(let t=Math.max(0,r-this.lookback(a));t<e.length;t++)this.writePoint(n,e,t,this.pointAt(e,t,a));i.length=e.length;for(let t=r;t<e.length;t++)i[t]=e[t].time;return n}},Qa=new Set([`compareSymbol`,`compareSymbolPane`,`spread`,`correlation`,`correlationlog`]),$a=e=>typeof e.params.symbol==`string`?e.params.symbol.trim():``,eo=class extends B{descriptor={id:`compareSymbol`,name:`Compare Symbol`,placement:`overlay`,defaultConfig:{symbol:``},shortName:`Compare`,plots:[{key:`value`,title:`Close`,color:0}],readsExchangeTimeZone:!1};constructor(e){super(),this.store=e}read(e){return{symbol:$a(e)}}pointAt(e,n,{symbol:r}){if(!r)return null;let i=this.store.closeAt(r,e[n].time,(0,t.barTimeUnit)(e));return i===void 0?null:{value:i}}},to=class extends eo{descriptor={id:`compareSymbolPane`,name:`Compare Symbol (Pane)`,placement:`panel`,defaultConfig:{symbol:``},shortName:`Compare`,plots:[{key:`value`,title:`Close`,color:0}],readsExchangeTimeZone:!1}},no=class extends B{descriptor={id:`spread`,name:`Spread / Ratio`,placement:`panel`,defaultConfig:{symbol:``,mode:`spread`},shortName:`Spread`,plots:[{key:`value`,title:`Spread`,color:0}],inputs:{mode:{options:[`spread`,`ratio`]}},readsExchangeTimeZone:!1};constructor(e){super(),this.store=e}read(e){return{symbol:$a(e),ratio:e.params.mode===`ratio`}}pointAt(e,n,{symbol:r,ratio:i}){if(!r)return null;let a=this.store.closeAt(r,e[n].time,(0,t.barTimeUnit)(e));return a===void 0?null:i?a===0?null:{value:e[n].close/a}:{value:e[n].close-a}}},ro=e=>{let t=Math.round(Number(e.params.length??20));return{symbol:$a(e),length:Number.isFinite(t)?Math.max(2,t):20}};function io(e,t){if(e.every(t=>t===e[0])||t.every(e=>e===t[0]))return null;let n=e.length,r=0,i=0;for(let a=0;a<n;a++)r+=e[a],i+=t[a];r/=n,i/=n;let a=0,o=0,s=0;for(let c=0;c<n;c++){let n=e[c]-r,l=t[c]-i;a+=n*l,o+=n*n,s+=l*l}return o>0&&s>0?Math.max(-1,Math.min(1,a/Math.sqrt(o*s))):null}var ao={placement:`panel`,defaultConfig:{symbol:``,length:20},inputs:{length:{kind:`int`,min:2}},plots:[{key:`value`,title:`Correlation`,color:0}],scale:{min:-1,max:1},levels:[0],readsExchangeTimeZone:!1},oo=class extends B{descriptor={...ao,id:`correlation`,name:`Correlation Coefficient`,shortName:`Correlation`};constructor(e){super(),this.store=e}read(e){return ro(e)}pointAt(e,n,{symbol:r,length:i}){if(!r||n<i-1)return null;let a=[],o=[];for(let s=n-i+1;s<=n;s++){let n=this.store.closeAt(r,e[s].time,(0,t.barTimeUnit)(e));if(n===void 0)return null;a.push(e[s].close),o.push(n)}let s=io(a,o);return s===null?null:{value:s}}},so=class extends B{descriptor={...ao,id:`correlationlog`,name:`Correlation Log`,shortName:`Correlation Log`};constructor(e){super(),this.store=e}read(e){return ro(e)}pointAt(e,n,{symbol:r,length:i}){if(!r||n<i)return null;let a=[],o=[],s=this.store.closeAt(r,e[n-i].time,(0,t.barTimeUnit)(e));for(let c=n-i+1;c<=n;c++){let n=this.store.closeAt(r,e[c].time,(0,t.barTimeUnit)(e)),i=e[c-1].close,l=e[c].close;if(n===void 0||s===void 0||!(i>0&&l>0&&n>0&&s>0))return null;a.push(Math.log(l/i)),o.push(Math.log(n/s)),s=n}let c=io(a,o);return c===null?null:{value:c}}};function co(e){let t=e.length,n={time:new Float64Array(t),open:new Float64Array(t),high:new Float64Array(t),low:new Float64Array(t),close:new Float64Array(t),volume:new Float64Array(t)};for(let r=0;r<t;r++){let t=e[r];n.time[r]=t.time,n.open[r]=t.open,n.high[r]=t.high,n.low[r]=t.low,n.close[r]=t.close,n.volume[r]=t.volume}return n}function lo(e){let{time:t,open:n,high:r,low:i,close:a,volume:o}=e,s=Array(t.length);for(let e=0;e<t.length;e++)s[e]={time:t[e],open:n[e],high:r[e],low:i[e],close:a[e],volume:o[e]};return s}function uo(e){let{time:t,open:n,high:r,low:i,close:a,volume:o}=e;return[t,n,r,i,a,o].map(e=>e.buffer)}function fo(e){let t=new Set;for(let n of e)if(n)for(let e in n)t.add(e);return[...t]}function po(e,t){if(e===t)return!0;let n=Object.keys(e);return n.length===Object.keys(t).length?n.every(n=>Object.is(e[n],t[n])):!1}function mo(e,t,n){if(t.length>n.length)return!1;let r=0;for(let i=0;i<t.length;i++){let a=t[i];if(!a)continue;r++;let o=e.values.get(n[i]);if(!o||!po(o,a))return!1}return r===e.values.size}function ho(e,t){let n=e.meta?{meta:e.meta}:{},r=e.series;if(!r)return{present:null,keys:[],columns:[],nans:[],values:new Map(e.values),...n};let i=fo(r),a=new Uint8Array(r.length),o=i.map(()=>new Float64Array(r.length).fill(NaN)),s=i.map(()=>null);for(let e=0;e<r.length;e++){let t=r[e];if(t){a[e]=1;for(let n=0;n<i.length;n++){let a=t[i[n]];a!==void 0&&(o[n][e]=a,Number.isNaN(a)&&((s[n]??=new Uint8Array(r.length))[e]=1))}}}return{present:a,keys:i,columns:o,nans:s,values:mo(e,r,t)?null:new Map(e.values),...n}}function go(e,t){let n={};for(let r=0;r<e.keys.length;r++){let i=e.columns[r][t];(!Number.isNaN(i)||e.nans[r]?.[t]===1)&&(n[e.keys[r]]=i)}return n}function _o(e,t){let[n,r,i,a]=e,[o,s,c,l]=t;switch(e.length){case 1:return n===`value`?e=>({value:o[e]}):e=>({[n]:o[e]});case 2:return e=>({[n]:o[e],[r]:s[e]});case 3:return e=>({[n]:o[e],[r]:s[e],[i]:c[e]});case 4:return e=>({[n]:o[e],[r]:s[e],[i]:c[e],[a]:l[e]});default:return null}}function vo(e,t){for(let n=0;n<e.length;n++)if(Number.isNaN(e[n][t]))return!1;return!0}var yo=class{next=0;series;full;keys=[];points=[];constructor(e,t){this.columns=e,this.time=t,this.series=Array(e.present?.length??0),this.full=_o(e.keys,e.columns)}step(e){let t=this.columns.present;if(!t)return!0;let n=Math.min(t.length,this.next+e),r=this.columns.values===null;for(let e=this.next;e<n;e++){if(t[e]===0){this.series[e]=null;continue}let n=this.full&&vo(this.columns.columns,e)?this.full(e):go(this.columns,e);this.series[e]=n,r&&(this.keys.push(this.time[e]),this.points.push(n))}return this.next=n,n===t.length}output(){let{columns:e}=this,t=e.meta?{meta:e.meta}:{};return e.present?{values:e.values??L.fromAscending(this.keys,this.points),series:this.series,...t}:{values:e.values??new Map,...t}}};function bo(e,t){let n=new yo(e,t);return n.step(1/0),n.output()}function xo(e){let t=e;return typeof t.workerState==`function`&&typeof t.adoptWorkerState==`function`}function So(e){return!!e&&typeof e==`object`&&e.tcPacked===`numbers`}function Co({values:e,missing:t}){let n=Array.from(e);if(t)for(let e=0;e<n.length;e++)t[e]===1&&(n[e]=void 0);return n}function wo(e){if(So(e))return Co(e);if(Array.isArray(e))return e.map(wo);if(!e||typeof e!=`object`)return e;let t={};for(let[n,r]of Object.entries(e))t[n]=wo(r);return t}var To=5e4;function Eo(e){let t=co(e);return{data:e,columns:t,times:t.time.slice()}}function Do(e,t,n,r,i,a){let o=0,s=e=>a(o,e),c=e.submit({indicatorId:t.descriptor.id,config:n,...i.kind===`price`?{source:i.source}:{},bars:r.columns,times:r.times},s);return c===null?null:(o=c,{requestId:o,data:r.data,times:r.times,from:1/0})}function Oo(e){let{data:t,times:n}=e,r=Math.min(e.from,n.length);return r===0||t.length<r?!1:t[0].time===n[0]&&t[r-1].time===n[r-1]}function ko(e,t,n,r,i){if(!Oo(e))return null;let a=t.output;xo(n)&&n.adoptWorkerState(a,t.state,e.times);let o=Math.min(e.from,e.times.length);return o===e.times.length&&e.data.length===o?a:n.update?.(i(),r,a,o)??null}var Ao=class{worker=null;jobs=new Map;sharedBars=null;constructor(e){this.host=e}use(e,t){this.settle(),this.worker=e?{client:e,minBars:t.minBars??5e4,onLand:t.onLand??null}:null}computing(e){if(e===void 0)return this.jobs.size>0;if(this.jobs.has(e))return!0;let t=this.host.instance(e);return!!t&&this.jobReadBy(t,this.jobs)!==null}stop(){this.worker?.client.cancel([...this.jobs.values()].map(e=>e.requestId)),this.jobs.clear(),this.worker=null}barsChanged(){this.sharedBars=null}takes(e,t,n){if(!this.worker&&this.jobs.size===0)return!1;let r=e.config.instanceId,i=this.jobs.get(r);return i&&n!==void 0?(i.from=Math.min(i.from,n),i.data=t,!0):(i&&this.drop(r),this.jobReadBy(e,this.jobs)?!0:n===void 0&&this.send(e,t))}drop(e){let t=this.jobs.get(e);t&&(this.jobs.delete(e),this.worker?.client.cancel([t.requestId]))}settle(){if(this.jobs.size===0)return;this.host.runPending();let e=this.jobs;this.jobs=new Map,this.worker?.client.cancel([...e.values()].map(e=>e.requestId));for(let t of this.host.ordered()){let n=e.get(t.config.instanceId)??this.jobReadBy(t,e);n&&this.host.compute(t,n.data,void 0,!0)}this.worker?.onLand?.()}send(e,t){let n=this.worker,{plugin:r,config:i}=e;if(!n?.client.usable||t.length<n.minBars||!Pa.has(r))return!1;let a=ya(r.descriptor,i.params);if(a.kind===`line`)return!1;let o=i.instanceId,s=this.barsFor(t),c=Do(n.client,r,i,s,a,(e,t)=>this.land(o,e,t));return c?(this.jobs.set(o,c),!0):!1}barsFor(e){let t=this.sharedBars;if(t?.data===e&&t.times.length===e.length)return t;let n=Eo(e);return this.sharedBars=n,queueMicrotask(()=>{this.sharedBars===n&&(this.sharedBars=null)}),n}jobReadBy(e,t){if(t.size===0)return null;let n=ya(e.plugin.descriptor,e.config.params),r=new Set;for(;n.kind===`line`&&!r.has(n.instanceId);){let e=t.get(n.instanceId);if(e)return e;r.add(n.instanceId);let i=this.host.instance(n.instanceId);if(!i)return null;n=ya(i.plugin.descriptor,i.config.params)}return null}land(e,t,n){let r=this.jobs.get(e);if(r?.requestId!==t)return;this.host.runPending();let i=this.host.instance(e);if(this.jobs.get(e)!==r||!i)return;this.jobs.delete(e),this.apply(i,r,n);let a=new Set(this.host.dependents(e));for(let e of this.host.ordered())a.has(e.config.instanceId)&&this.host.compute(e,r.data);this.worker?.onLand?.()}apply(e,t,n){let{plugin:r,config:i}=e;delete e.sourceBars;let a=n instanceof Error?null:n,o=a&&ko(t,a,r,i,()=>jo(e,t.data));if(!o){this.host.compute(e,t.data,void 0,!0);return}e.output=o,e.changedFrom=0}};function jo(e,t){let n=ya(e.plugin.descriptor,e.config.params);return n.kind===`price`?(e.sourceBars=ba(t,n.source),e.sourceBars):t}var Mo=1;function No(e){return e.descriptor.readsExchangeTimeZone??!Pa.has(e)}var Po=class{registry=new Map;instances=new Map;styleDefaults=new Map;order=null;pending=null;timeframe=null;exchangeTimeZone=null;barsTimed=!0;worker=new Ao({instance:e=>this.instances.get(e),ordered:()=>this.ordered(),dependents:e=>this.getDependents(e),compute:(e,t,n,r)=>this.compute(e,t,n,r),runPending:()=>this.runPending()});useWorker(e,t={}){this.worker.use(e,t)}register(e){this.registry.set(e.descriptor.id,e)}getAvailableIndicators(){return Array.from(this.registry.values()).map(e=>e.descriptor)}addIndicator(e,t={},n,r={}){let i=this.registry.get(e);if(!i)throw Error(`Unknown indicator: ${e}`);let a=this.claimInstanceId(e,r.instanceId),o={id:e,instanceId:a,params:{...i.descriptor.defaultConfig,...t},visible:!0};r.pane&&this.canHost(r.pane)&&(o.pane=r.pane),r.scale===`left`&&i.descriptor.placement===`overlay`&&!o.pane&&(o.scale=`left`),this.exchangeTimeZone&&(o.exchangeTimeZone=this.exchangeTimeZone);let s=this.styleDefaults.get(e),c={...s?.plots,...o.style?.plots},l={colors:o.style?.colors??s?.colors?.slice()??Aa(_a([...this.instances.values()],e,i.descriptor.placement,o.pane??null)),lineWidths:o.style?.lineWidths??s?.lineWidths?.slice()??[1.5],opacity:o.style?.opacity??s?.opacity??1,...Object.keys(c).length>0?{plots:Ma(c)}:{}};this.runPending();let u={plugin:i,config:o,output:null,style:l,changedFrom:0,offInterval:!1,offChartType:!1};return this.placeOnChartType(u),this.instances.set(a,u),this.order=null,n&&this.compute(u,n),a}removeIndicator(e){this.worker.drop(e),this.instances.delete(e),this.order=null}updateIndicator(e,t,n){this.runPending();let r=this.instances.get(e);if(!r)return;let i=va(r.plugin.descriptor);if(i&&i in t&&this.readsFromItself(e,{...r.config.params,...t})){let{[i]:e,...n}=t;t=n}if(Object.assign(r.config.params,t),delete r.sourceBars,delete r.lineInput,this.order=null,!n)return;let a=new Set([e,...this.getDependents(e)]);for(let e of this.ordered())a.has(e.config.instanceId)&&this.compute(e,n)}recalculateAll(e){this.pending=null;for(let t of this.ordered())this.compute(t,e)}deferRecalculateFrom(e,t){this.worker.barsChanged();let n=this.waitingOn(e);n.from=Math.min(n.from,t)}waitingOn(e){let t=this.pending;return t&&t.data===e?t:(this.runPending(),this.pending={data:e,from:1/0,full:new Set},this.pending)}flush(){this.worker.settle(),this.runPending()}runPending(){let e=this.pending;if(!e)return;this.pending=null;let{data:t,from:n,full:r}=e;for(let e of this.ordered())r.has(e.config.instanceId)?this.compute(e,t):n!==1/0&&this.compute(e,t,n)}recalculateFrom(e,t){this.deferRecalculateFrom(e,t),this.runPending()}compute(e,t,n,r=!1){if(!r&&this.worker.takes(e,t,n))return;let{plugin:i,config:a}=e,o=ya(i.descriptor,a.params);if(o.kind===`line`){this.computeFromLine(e,t,o.instanceId,o.key,n);return}delete e.lineInput;let s=t;o.kind===`price`?(e.sourceBars=ba(t,o.source,e.sourceBars??null,n??0),s=e.sourceBars):delete e.sourceBars;let c=e.output,l=null;n!==void 0&&n>0&&c&&i.update&&(l=i.update(s,a,c,n)),e.changedFrom=l?Math.max(0,n-(i.revisesBefore?.(a)??0)):0,e.output=l??i.calculate(s,a)}computeFromLine(e,t,n,r,i){let{plugin:a,config:o}=e,s=this.instances.get(n),c=s?.output?.series,l=e.lineInput,u=i===void 0?void 0:Math.min(i,s?.changedFrom??0);if(u!==void 0&&c&&a.update&&l&&l.raw.series&&l.aligned.series&&l.sourceId===n&&l.key===r&&l.start<u&&u<=l.start+l.bars.length){let{start:n,bars:i}=l;i.length=t.length-n;let s=i[u-1-n].close;for(let e=u;e<t.length;e++){let a=c[e]?.[r];a!==void 0&&Number.isFinite(a)&&(s=a),i[e-n]={time:t[e].time,open:s,high:s,low:s,close:s,volume:t[e].volume}}let d=a.update(i,o,l.raw,u-n);if(d?.series){let r=Math.max(n,u-(a.revisesBefore?.(o)??0));if(l.raw=d,n===0)l.aligned=d;else{let e=l.aligned.series;e.length=t.length;for(let i=r;i<t.length;i++)e[i]=d.series[i-n]??null;l.aligned.values=d.values,l.aligned.meta=d.meta}e.output=l.aligned,e.changedFrom=r;return}}e.changedFrom=0;let d=xa(t,c,r);if(!d){delete e.lineInput,e.output=Ca(t.length);return}let f=a.calculate(d.bars,o),p=Sa(f,d.start,t.length);e.lineInput={sourceId:n,key:r,start:d.start,bars:d.bars,raw:f,aligned:p},e.output=p}ordered(){if(this.order)return this.order;let e=[],t=new Map,n=r=>{let i=r.config.instanceId;if(t.get(i))return;t.set(i,`visiting`);let a=ya(r.plugin.descriptor,r.config.params),o=a.kind===`line`?this.instances.get(a.instanceId):void 0;o&&n(o),t.set(i,`done`),e.push(r)};for(let e of this.instances.values())n(e);return this.order=e,e}readsFromItself(e,t){let n=this.instances.get(e);if(!n)return!1;let r=ya(n.plugin.descriptor,t),i=new Set;for(;r.kind===`line`;){if(r.instanceId===e)return!0;if(i.has(r.instanceId))return!1;i.add(r.instanceId);let t=this.instances.get(r.instanceId);if(!t)return!1;r=ya(t.plugin.descriptor,t.config.params)}return!1}canHost(e){let t=this.instances.get(e);return!!t&&t.plugin.descriptor.placement===`panel`&&!t.config.pane}getDependents(e){let t=[],n=new Set([e]),r=[e];for(;r.length;){let e=r.shift();for(let i of this.instances.values()){let a=ya(i.plugin.descriptor,i.config.params),o=i.config.instanceId;a.kind===`line`&&a.instanceId===e&&!n.has(o)&&(n.add(o),t.push(o),r.push(o))}}return t}claimInstanceId(e,t){if(t&&!this.instances.has(t)){let e=Number(/_(\d+)$/.exec(t)?.[1]);return Number.isSafeInteger(e)&&e>=Mo&&(Mo=e+1),t}let n=`tc_${e}_${Mo++}`;for(;this.instances.has(n);)n=`tc_${e}_${Mo++}`;return n}getPaneMembers(e){let t=[];for(let n of this.instances.values())n.config.pane===e&&t.push(n.config.instanceId);return t}setPane(e,t){let n=this.instances.get(e);if(!n||t===e||t!==null&&!this.canHost(t))return!1;if(t===null?delete n.config.pane:(n.config.pane=t,delete n.config.scale),ja(n.style.colors)){let t=n.plugin.descriptor.placement,r=n.config.pane??null,i=[...this.instances.values()];ga(i,t,r,e).has(n.style.colors[0])&&(n.style.colors=Aa(_a(i,n.config.id,t,r,e)))}return!0}getOutput(e){return this.flush(),this.instances.get(e)?.output??null}peekOutput(e){return this.runPending(),this.instances.get(e)?.output??null}isComputingInWorker(e){return this.worker.computing(e)}stopWorker(){this.worker.stop()}renderOverlays(e,t,n){for(let r of this.overlayDraws(t,n))r(e)}overlayDraws(e,t){this.runPending();let n=[];for(let r of this.instances.values()){let i=r.output;if(!i||!oa(r)||r.plugin.descriptor.placement!==`overlay`||r.config.pane)continue;let a=r.config.scale===`left`?t??e:e;n.push(e=>r.plugin.render(e,i,a,r.style))}return n}hasLeftScaleOverlays(){return[...this.instances.values()].some(e=>e.config.scale===`left`&&oa(e))}setScale(e,t){let n=this.instances.get(e);return!n||n.plugin.descriptor.placement!==`overlay`||n.config.pane?!1:(t===`left`?n.config.scale=`left`:delete n.config.scale,!0)}renderPanel(e,t,n){this.runPending();let r=this.instances.get(t);!r?.output||!oa(r)||r.plugin.render(e,r.output,n,r.style)}getLatestValues(e){this.runPending();let t=this.instances.get(e);return t?la(t):[]}getLatestOverlayValues(e=`right`){return this.runPending(),ua(this.instances.values(),e)}getIndicatorConfig(e){return this.instances.get(e)?.config??null}setVisible(e,t){let n=this.instances.get(e);return n?(n.config.visible=t,t):null}isVisible(e){return this.instances.get(e)?.config.visible??!1}isShown(e){let t=this.instances.get(e);return t?oa(t):!1}setTimeframe(e){this.timeframe=e;let t=!1;for(let e of this.instances.values())t=this.placeOnInterval(e)||t;return t}setExchangeTimeZone(e,n){let r=e&&!(0,t.isUtcTimeZone)(e)&&(0,t.isValidTimeZone)(e)?e:null;if(r===this.exchangeTimeZone)return!1;this.exchangeTimeZone=r;for(let{config:e}of this.instances.values())r?e.exchangeTimeZone=r:delete e.exchangeTimeZone;if(n){let e=this.waitingOn(n).full;for(let t of this.zoneDependents())e.add(t)}return!0}zoneDependents(){let e=new Set;for(let t of this.instances.values())if(No(t.plugin)){e.add(t.config.instanceId);for(let n of this.getDependents(t.config.instanceId))e.add(n)}return e}setIntervals(e,t){let n=this.instances.get(e);if(!n)return!1;let r=t?ka(t):null;return r?n.config.intervals=r:delete n.config.intervals,this.placeOnInterval(n),!0}getIntervals(e){let t=this.instances.get(e)?.config.intervals;return t?Na(t):null}setBarsTimed(e){if(e===this.barsTimed)return!1;this.barsTimed=e;let t=!1;for(let e of this.instances.values())t=this.placeOnChartType(e)||t;return t}placeOnChartType(e){let t=Qa.has(e.config.id)||e.plugin.descriptor.readsExchangeTimeZone===!0,n=!this.barsTimed&&t;return n===e.offChartType?!1:(e.offChartType=n,!0)}placeOnInterval(e){let t=!Oa(e.config.intervals,this.timeframe);return t===e.offInterval?!1:(e.offInterval=t,!0)}getLevels(e){let t=this.instances.get(e);return t?[...t.config.levels??t.plugin.descriptor.levels??[]]:[]}setLevels(e,t){let n=this.instances.get(e);return n?(t===null?delete n.config.levels:n.config.levels=t.filter(e=>Number.isFinite(e)),!0):!1}getPaneValueRange(e,t,n,r=!1){return this.runPending(),da(this.paneInstances(e),t,n,r)}getPaneValuesAt(e,t){return this.runPending(),fa(this.paneInstances(e),t)}paneInstances(e){return[e,...this.getPaneMembers(e)].map(e=>this.instances.get(e)).filter(e=>e!==void 0)}getIndicatorDescriptor(e){return this.instances.get(e)?.plugin.descriptor??null}getActiveIndicators(){let e=[];for(let[t,n]of this.instances)e.push({instanceId:t,id:n.config.id,params:{...n.config.params},descriptor:n.plugin.descriptor,visible:n.config.visible??!0,shown:oa(n),...n.offChartType?{offChartType:!0}:{},...n.config.intervals?{intervals:Na(n.config.intervals)}:{},...n.config.pane?{pane:n.config.pane}:{},...n.config.scale===`left`?{scale:`left`}:{}});return e}orderIndicators(e){let t=new Map;for(let n of e){let e=this.instances.get(n);e&&!t.has(n)&&t.set(n,e)}for(let[e,n]of this.instances)t.has(e)||t.set(e,n);this.instances=t,this.order=null}getIndicatorStyle(e){let t=this.instances.get(e)?.style;return t?{colors:[...t.colors],lineWidths:[...t.lineWidths],opacity:t.opacity,...t.plots?{plots:Ma(t.plots)}:{}}:null}updateIndicatorStyle(e,t){let n=this.instances.get(e);if(!n)return;let{plots:r,...i}=t;if(Object.assign(n.style,i),r){let e=Ma(n.style.plots??{});for(let[t,n]of Object.entries(r))e[t]={...e[t],...n};n.style.plots=e}}setPlotStyles(e,t){let n=this.instances.get(e);n&&(t&&Object.keys(t).length>0?n.style.plots=Ma(t):delete n.style.plots)}setStyleDefaults(e,t){t?this.styleDefaults.set(e,{...t,...t.plots?{plots:Ma(t.plots)}:{}}):this.styleDefaults.delete(e)}getOverlayPriceRange(e,t,n=`right`){return this.runPending(),ha(this.instances.values(),e,t,n)}getPanelIndicators(){return[...this.instances.values()].filter(e=>e.plugin.descriptor.placement===`panel`).map(e=>({instanceId:e.config.instanceId,descriptor:e.plugin.descriptor}))}};function V(e,t,n){let r=e.params[t];if(typeof r==`number`&&Number.isFinite(r))return r;if(typeof r==`string`){let e=Number(r);if(Number.isFinite(e))return e}return n}function H(e,t,n,r=1){let i=V(e,t,n);return Math.max(r,Math.floor(i))}var Fo=class extends I{descriptor={id:`sma`,name:`Simple Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`SMA`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`SMA`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null),a=0;for(let t=0;t<e.length;t++)if(a+=e[t].close,t>=n&&(a-=e[t-n].close),t>=n-1){let o={value:a/n};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=H(t,`period`,20,1);for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0;for(let n=t-i+1;n<=t;n++)r+=e[n].close;this.writePoint(n,e,t,{value:r/i})}return n}},Io=class extends I{descriptor={id:`ema`,name:`Exponential Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`EMA`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`EMA`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=2/(n+1),i=new L,a=Array(e.length).fill(null),o=0;for(let t=0;t<e.length;t++){if(t<n-1){o+=e[t].close;continue}o=t===n-1?(o+e[t].close)/n:(e[t].close-o)*r+o;let s={value:o};i.set(e[t].time,s),a[t]=s}return{values:i,series:a}}update(e,t,n,r){let i=H(t,`period`,20,1);if(r<i||!this.canResume(e,n,r))return null;let a=n.series[r-1]?.value;if(a===void 0)return null;let o=2/(i+1);for(let t=r;t<e.length;t++)a=(e[t].close-a)*o+a,this.writePoint(n,e,t,{value:a});return n}},Lo=class extends I{descriptor={id:`bb`,name:`Bollinger Bands`,placement:`overlay`,defaultConfig:{period:20,stdDev:2,source:`close`},shortName:`BB`,inputs:{source:{source:!0},period:{kind:`int`,min:1},stdDev:{kind:`number`,min:.1,step:.1}},fills:[{between:[`upper`,`lower`],color:0,opacity:.1}],plots:[{key:`upper`,title:`Upper`,color:0},{key:`middle`,title:`Basis`,color:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=V(t,`stdDev`,2),i=new L,a=Array(e.length).fill(null),o=0,s=0;for(let t=0;t<e.length;t++){let c=e[t].close;if(o+=c,s+=c*c,t>=n){let r=e[t-n].close;o-=r,s-=r*r}if(t>=n-1){let c=o/n,l=s/n-c*c,u=Math.sqrt(Math.max(0,l)),d={middle:c,upper:c+r*u,lower:c-r*u};i.set(e[t].time,d),a[t]=d}}return{values:i,series:a}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=H(t,`period`,20,1),a=V(t,`stdDev`,2);for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0,o=0;for(let n=t-i+1;n<=t;n++){let t=e[n].close;r+=t,o+=t*t}let s=r/i,c=Math.sqrt(Math.max(0,o/i-s*s));this.writePoint(n,e,t,{middle:s,upper:s+a*c,lower:s-a*c})}return n}},Ro=[`session`,`week`,`month`,`all`],zo=64,Bo=2;function Vo(e){let t=e.params.anchor;return Ro.includes(t)?t:`session`}function Ho(e,t){let n=Vo(t);return n===`all`?null:Dt(e,n,t.exchangeTimeZone)}var Uo=class extends I{descriptor={readsExchangeTimeZone:!0,id:`vwap`,name:`Volume Weighted Average Price`,placement:`overlay`,defaultConfig:{anchor:`session`},shortName:`VWAP`,inputs:{anchor:{options:Ro}},plots:[{key:`value`,title:`VWAP`,color:0,breakOn:`session`}]};kept=new WeakMap;workerState(e){return this.kept.get(e)}adoptWorkerState(e,t){t&&this.kept.set(e,t)}calculate(e,t){let n={values:new L,series:Array(e.length).fill(null)},r=Ho(e,t),i=this.fill(n,e,r,0,null);return r&&this.kept.set(n,i),n}update(e,t,n,r){let i=Ho(e,t),a=this.kept.get(n)??[],o=a.find(e=>e.index===r-1);if(!i||!o||r<zo||r>=e.length||!this.canResume(e,n,r))return null;n.series.length=e.length;let s=this.fill(n,e,i,r,o),c=a.filter(t=>t.index<r&&t.index>=e.length-Bo);return this.kept.set(n,[...c,...s]),n}fill(e,t,n,r,i){let a=i&&n?n(t[i.index].time):void 0,o=i?.volume??0,s=i?.volumePrice??0,c=[];for(let i=r;i<t.length;i++){let r=t[i];if(n){let e=n(r.time);e!==a&&(o=0,s=0,a=e)}o+=r.volume,s+=(r.high+r.low+r.close)/3*r.volume,i>=t.length-Bo&&c.push({index:i,volume:o,volumePrice:s});let l=o>0?a===void 0?{value:s/o}:{value:s/o,session:a}:null;this.writePoint(e,t,i,l)}return c}},Wo=4,Go=t.TC_SERIES_COLORS[Wo],Ko=class extends I{descriptor={id:`ichimoku`,name:`Ichimoku Cloud`,placement:`overlay`,defaultConfig:{tenkan:9,kijun:26,senkou:52,displacement:26},inputs:{tenkan:{kind:`int`,min:1},kijun:{kind:`int`,min:1},senkou:{kind:`int`,min:1},displacement:{kind:`int`,min:0}},shortName:`Ichimoku`,plots:[{key:`tenkan`,title:`Conversion`,color:0},{key:`kijun`,title:`Base`,color:1},{key:`senkouA`,title:`Lead A`,color:2},{key:`senkouB`,title:`Lead B`,color:3},{key:`chikou`,title:`Lagging Span`,color:Wo}]};calculate(e,t){let n=H(t,`tenkan`,9,1),r=H(t,`kijun`,26,1),i=H(t,`senkou`,52,1),a=H(t,`displacement`,26,0),o=new L,s=Array(e.length).fill(null),c=t=>{let n=new Float64Array(e.length),r=new Float64Array(e.length);for(let i=0;i<e.length;i++){let a=-1/0,o=1/0,s=Math.max(0,i-t+1);for(let t=s;t<=i;t++)e[t].high>a&&(a=e[t].high),e[t].low<o&&(o=e[t].low);n[i]=a,r[i]=o}return{highs:n,lows:r}},l=c(n),u=c(r),d=c(i),f=(e,t,n)=>n>=t-1?(e.highs[n]+e.lows[n])/2:void 0,p=e=>{let t=f(l,n,e),a=f(u,r,e),o={};t!==void 0&&a!==void 0&&(o.senkouA=(t+a)/2);let s=f(d,i,e);return s!==void 0&&(o.senkouB=s),o};for(let t=0;t<e.length;t++){let i={},c=f(l,n,t);c!==void 0&&(i.tenkan=c);let d=f(u,r,t);d!==void 0&&(i.kijun=d),t>=a&&Object.assign(i,p(t-a)),t+a<e.length&&(i.chikou=e[t+a].close),Object.keys(i).length>0&&(o.set(e[t].time,i),s[t]=i)}let m=Math.max(0,e.length-a),h=[];for(let t=m;t<e.length;t++)h.push(p(t));return{values:o,series:s,meta:{ahead:h,aheadFrom:m+a}}}render(n,r,i,a){let o=r.series;if(!o)return;let{from:s,to:c}=i.visibleRange,l=r.meta?.ahead,u=r.meta?.aheadFrom??o.length,d=c-s+1,f=d+(l?.length??0),p=new Float64Array(d),m=new Float64Array(d),h=0,g=new Float64Array(d),_=new Float64Array(d),v=0,y=new Float64Array(f),b=new Float64Array(f),x=0,S=new Float64Array(f),C=new Float64Array(f),w=0,T=new Float64Array(d),E=new Float64Array(d),D=0,O=new Float64Array(f),k=new Float64Array(f),A=new Float64Array(f),j=0,ee=(t,n)=>{let r=n.senkouA,a=n.senkouB;r!==void 0&&(y[x]=t,b[x]=e.T(r,i),x++),a!==void 0&&(S[w]=t,C[w]=e.T(a,i),w++),r!==void 0&&a!==void 0&&(O[j]=t,k[j]=b[x-1],A[j]=C[w-1],j++)};for(let t=s;t<=c&&t<o.length;t++){let n=o[t];if(!n)continue;let r=e.b(t,i);n.tenkan!==void 0&&(p[h]=r,m[h]=e.T(n.tenkan,i),h++),n.kijun!==void 0&&(g[v]=r,_[v]=e.T(n.kijun,i),v++),ee(r,n),n.chikou!==void 0&&(T[D]=r,E[D]=e.T(n.chikou,i),D++)}if(l){let t=i.chartRect.x-i.barWidth-i.barSpacing,n=i.chartRect.x+i.chartRect.width+i.barWidth+i.barSpacing;for(let r=0;r<l.length;r++){let a=e.b(u+r,i);if(a>n)break;a>=t&&ee(a,l[r])}}if(j>1){n.beginPath(),n.moveTo(O[0],k[0]);for(let e=1;e<j;e++)n.lineTo(O[e],k[e]);for(let e=j-1;e>=0;e--)n.lineTo(O[e],A[e]);n.closePath(),n.fillStyle=(0,t.withAlpha)(a.colors[2]??`#1fa874`,.15),n.fill()}let te=(e,t,r,i,o,s)=>{let c=Ki(a,e,s);if(!(i<2||!c.visible)){n.beginPath(),n.strokeStyle=o,n.lineWidth=s,n.lineJoin=`round`,n.setLineDash(c.dash),n.moveTo(t[0],r[0]);for(let e=1;e<i;e++)n.lineTo(t[e],r[e]);n.stroke(),n.setLineDash([])}};te(`tenkan`,p,m,h,a.colors[0],a.lineWidths[0]),te(`kijun`,g,_,v,a.colors[1]??`#f2a93b`,a.lineWidths[0]),te(`senkouA`,y,b,x,a.colors[2]??`#1fa874`,1),te(`senkouB`,S,C,w,a.colors[3]??`#e8505b`,1),te(`chikou`,T,E,D,a.colors[Wo]??Go,1)}},qo=class extends I{descriptor={id:`psar`,name:`Parabolic SAR`,placement:`overlay`,defaultConfig:{step:.02,max:.2},inputs:{step:{kind:`number`,min:.01,step:.01},max:{kind:`number`,min:.01,step:.01}},shortName:`SAR`,plots:[{key:`value`,title:`SAR`,color:0,kind:`dots`,tone:{field:`trend`},downColor:1}]};calculate(e,t){let n=V(t,`step`,.02),r=V(t,`max`,.2),i=new L,a=Array(e.length).fill(null);if(e.length<2)return{values:i,series:a};let o=e[1].close>e[0].close,s=n,c=o?e[0].high:e[0].low,l=o?e[0].low:e[0].high,u={value:l,trend:o?1:-1};i.set(e[0].time,u),a[0]=u;for(let t=1;t<e.length;t++){let u=l;l=u+s*(c-u),o?(l=Math.min(l,e[t-1].low),t>=2&&(l=Math.min(l,e[t-2].low)),e[t].low<l?(o=!1,l=c,c=e[t].low,s=n):e[t].high>c&&(c=e[t].high,s=Math.min(s+n,r))):(l=Math.max(l,e[t-1].high),t>=2&&(l=Math.max(l,e[t-2].high)),e[t].high>l?(o=!0,l=c,c=e[t].high,s=n):e[t].low<c&&(c=e[t].low,s=Math.min(s+n,r)));let d={value:l,trend:o?1:-1};i.set(e[t].time,d),a[t]=d}return{values:i,series:a}}},Jo=class extends I{descriptor={id:`supertrend`,name:`Supertrend`,placement:`overlay`,defaultConfig:{period:10,multiplier:3},inputs:{period:{kind:`int`,min:1},multiplier:{kind:`number`,min:.1,step:.1}},shortName:`Supertrend`,plots:[{key:`value`,title:`Supertrend`,color:0,tone:{field:`trend`},downColor:1}]};calculate(e,t){let n=H(t,`period`,10,1),r=V(t,`multiplier`,3),i=new L,a=Array(e.length).fill(null);if(e.length<n)return{values:i,series:a};let o=[e[0].high-e[0].low];for(let t=1;t<e.length;t++)o.push(Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close)));let s=0;for(let e=0;e<n;e++)s+=o[e];s/=n;let c=0,l=0,u=0,d=0,f=0,p=0,m=1;for(let t=n-1;t<e.length;t++){t>n-1&&(s=(s*(n-1)+o[t])/n);let h=(e[t].high+e[t].low)/2,g=h+r*s,_=h-r*s,v=e[Math.max(0,t-1)].close;c=g<u||v>u?g:u,l=_>d||v<d?_:d,f=p===u?e[t].close<=c?c:l:e[t].close>=l?l:c,m=f===l?1:-1;let y={value:f,trend:m};i.set(e[t].time,y),a[t]=y,u=c,d=l,p=f}return{values:i,series:a}}},Yo=class extends I{descriptor={id:`keltner`,name:`Keltner Channel`,placement:`overlay`,defaultConfig:{emaPeriod:20,atrPeriod:10,multiplier:1.5},inputs:{emaPeriod:{kind:`int`,min:1},atrPeriod:{kind:`int`,min:1},multiplier:{kind:`number`,min:.1,step:.1}},shortName:`KC`,fills:[{between:[`upper`,`lower`],color:0,opacity:.08}],plots:[{key:`upper`,title:`Upper`,color:0},{key:`middle`,title:`Basis`,color:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=H(t,`emaPeriod`,20,1),r=H(t,`atrPeriod`,10,1),i=V(t,`multiplier`,1.5),a=new L;if(e.length<Math.max(n,r))return{values:a};let o=2/(n+1),s=e[0].close,c=[s];for(let t=1;t<e.length;t++)s=(e[t].close-s)*o+s,c.push(s);let l=[e[0].high-e[0].low];for(let t=1;t<e.length;t++)l.push(Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close)));let u=0;for(let e=0;e<r;e++)u+=l[e];u/=r;let d=Array(e.length).fill(null),f=Math.max(n,r)-1;for(let t=f;t<e.length;t++){t>f&&(u=(u*(r-1)+l[t])/r);let n={middle:c[t],upper:c[t]+i*u,lower:c[t]-i*u};a.set(e[t].time,n),d[t]=n}return{values:a,series:d}}},Xo=class extends I{descriptor={id:`donchian`,name:`Donchian Channel`,placement:`overlay`,defaultConfig:{period:20},inputs:{period:{kind:`int`,min:1}},shortName:`DC`,fills:[{between:[`upper`,`lower`],color:0,opacity:.08}],plots:[{key:`upper`,title:`Upper`,color:0},{key:`middle`,title:`Basis`,color:1,width:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s={upper:a,middle:(a+o)/2,lower:o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}},Zo=[`traditional`,`fibonacci`,`woodie`,`classic`,`camarilla`,`dm`],Qo=class extends I{descriptor={id:`pivots`,name:`Pivot Points`,placement:`overlay`,defaultConfig:{lookback:24,type:`traditional`},shortName:`Pivots`,inputs:{lookback:{kind:`int`,min:1},type:{options:Zo}},plots:[{key:`r3`,title:`R3`,color:1,width:1,lineStyle:`dashed`},{key:`r2`,title:`R2`,color:1,width:1,lineStyle:`dashed`},{key:`r1`,title:`R1`,color:1,width:1,lineStyle:`dashed`},{key:`pp`,title:`P`,color:0},{key:`s1`,title:`S1`,color:2,width:1,lineStyle:`dashed`},{key:`s2`,title:`S2`,color:2,width:1,lineStyle:`dashed`},{key:`s3`,title:`S3`,color:2,width:1,lineStyle:`dashed`}]};calculate(e,t){let n=H(t,`lookback`,24,1),r=Zo.includes(t.params.type)?t.params.type:`traditional`,i=new L,a=Array(e.length).fill(null);if(e.length<=n)return{values:i,series:a};for(let t=n;t<e.length;t++){let o=-1/0,s=1/0;for(let r=t-n;r<t;r++)e[r].high>o&&(o=e[r].high),e[r].low<s&&(s=e[r].low);let c=$o(r,e[t-n].open,o,s,e[t-1].close);i.set(e[t].time,c),a[t]=c}return{values:i,series:a}}};function $o(e,t,n,r,i){let a=n-r;if(e===`dm`){let e=i<t?n+2*r+i:i>t?2*n+r+i:n+r+2*i;return{pp:e/4,r1:e/2-r,s1:e/2-n}}if(e===`camarilla`){let e=a*1.1;return{pp:(n+r+i)/3,r1:i+e/12,s1:i-e/12,r2:i+e/6,s2:i-e/6,r3:i+e/4,s3:i-e/4}}let o=e===`woodie`?(n+r+2*i)/4:(n+r+i)/3;if(e===`fibonacci`)return{pp:o,r1:o+.382*a,s1:o-.382*a,r2:o+.618*a,s2:o-.618*a,r3:o+a,s3:o-a};let s=2*o-r,c=2*o-n;return e===`classic`?{pp:o,r1:s,s1:c,r2:o+a,s2:o-a,r3:o+2*a,s3:o-2*a}:{pp:o,r1:s,s1:c,r2:o+a,s2:o-a,r3:n+2*(o-r),s3:r-2*(n-o)}}var es=class extends I{descriptor={id:`avwap`,name:`Anchored VWAP`,placement:`overlay`,defaultConfig:{anchorTime:0},inputs:{anchorTime:{kind:`int`}},shortName:`AVWAP`,plots:[{key:`value`,title:`AVWAP`,color:0}]};calculate(e,n){let r=V(n,`anchorTime`,0),i=new L,a=Array(e.length).fill(null),o=0;if(r>0){let n=(0,t.barTimeUnit)(e),s=(0,t.normalizeBarTime)(r);if(o=e.findIndex(e=>e.time*n>=s),o<0)return{values:i,series:a}}let s=0,c=0;for(let t=o;t<e.length;t++){let n=(e[t].high+e[t].low+e[t].close)/3;if(s+=e[t].volume,c+=n*e[t].volume,s>0){let n={value:c/s};i.set(e[t].time,n),a[t]=n}}return{values:i,series:a}}},ts=class extends I{descriptor={id:`zigzag`,name:`ZigZag`,placement:`overlay`,defaultConfig:{deviation:5},inputs:{deviation:{kind:`number`,min:.1,step:.1}},shortName:`ZigZag`,plots:[{key:`pivot`,title:`Pivot`,color:0}]};calculate(e,t){let n=Math.max(.01,V(t,`deviation`,5))/100,r=new L,i=Array(e.length).fill(null);if(e.length<2)return{values:r,series:i,meta:{pivots:[]}};let a=[],o=null,s=0,c=e[0].close;for(let t=1;t<e.length;t++){let r=e[t].high,i=e[t].low;if(o===null){r>=c*(1+n)?(a.push({idx:s,price:c,type:`low`}),o=`up`,s=t,c=r):i<=c*(1-n)&&(a.push({idx:s,price:c,type:`high`}),o=`down`,s=t,c=i);continue}o===`up`?r>c?(s=t,c=r):i<=c*(1-n)&&(a.push({idx:s,price:c,type:`high`}),o=`down`,s=t,c=i):i<c?(s=t,c=i):r>=c*(1+n)&&(a.push({idx:s,price:c,type:`low`}),o=`up`,s=t,c=r)}a.push({idx:s,price:c,type:o===`up`?`high`:`low`});for(let t of a){let n={pivot:t.price};r.set(e[t.idx].time,n),i[t.idx]=n}return{values:r,series:i,meta:{pivots:a}}}render(t,n,r,i){if(i.plots?.pivot?.visible===!1)return;let a=n.meta?.pivots;if(!(!a||a.length<2)){t.beginPath(),t.strokeStyle=i.colors[0],t.lineWidth=i.lineWidths[0],t.lineJoin=`round`;for(let n=0;n<a.length;n++){let i=a[n],o=e.b(i.idx,r),s=e.T(i.price,r);n===0?t.moveTo(o,s):t.lineTo(o,s)}t.stroke()}}},ns=class extends I{descriptor={id:`lrc`,name:`Linear Regression Channel`,placement:`overlay`,defaultConfig:{period:100,stdDev:2,source:`close`},shortName:`LRC`,inputs:{source:{source:!0},period:{kind:`int`,min:2},stdDev:{kind:`number`,min:.1,step:.1}},fills:[{between:[`upper`,`lower`],color:0,opacity:.08}],plots:[{key:`upper`,title:`Upper`,color:0},{key:`middle`,title:`Basis`,color:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=H(t,`period`,100,2),r=V(t,`stdDev`,2),i=new L,a=Array(e.length).fill(null);if(e.length<n)return{values:i,series:a};for(let t=n-1;t<e.length;t++){let o=t-n+1,s=0,c=0,l=0,u=0;for(let t=0;t<n;t++){let n=t,r=e[o+t].close;s+=n,c+=r,l+=n*r,u+=n*n}let d=n*u-s*s;if(d===0)continue;let f=(n*l-s*c)/d,p=(c-f*s)/n,m=0;for(let t=0;t<n;t++){let n=f*t+p,r=e[o+t].close-n;m+=r*r}let h=Math.sqrt(m/n),g=f*(n-1)+p,_={middle:g,upper:g+r*h,lower:g-r*h,slope:f};i.set(e[t].time,_),a[t]=_}return{values:i,series:a}}},rs=class extends I{descriptor={id:`hma`,name:`Hull Moving Average`,placement:`overlay`,defaultConfig:{period:21,source:`close`},shortName:`HMA`,inputs:{source:{source:!0},period:{kind:`int`,min:2}},plots:[{key:`value`,title:`HMA`,color:0}]};calculate(e,t){let n=H(t,`period`,21,2),r=new L,i=Array(e.length).fill(null);if(e.length<n)return{values:r,series:i};let a=e.map(e=>e.close),o=Math.max(2,Math.floor(n/2)),s=Math.max(2,Math.floor(Math.sqrt(n))),c=is(a,n),l=is(a,o),u=as(a.map((e,t)=>c[t]===null||l[t]===null?null:2*l[t]-c[t]),s);for(let t=0;t<e.length;t++){if(u[t]===null)continue;let n={value:u[t]};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}};function is(e,t){let n=Array(e.length).fill(null);if(e.length<t)return n;let r=t*(t+1)/2;for(let i=t-1;i<e.length;i++){let a=0;for(let n=0;n<t;n++)a+=e[i-n]*(t-n);n[i]=a/r}return n}function as(e,t){let n=Array(e.length).fill(null),r=t*(t+1)/2;for(let i=t-1;i<e.length;i++){let a=0,o=!0;for(let n=0;n<t;n++){let r=e[i-n];if(r===null){o=!1;break}a+=r*(t-n)}o&&(n[i]=a/r)}return n}var os=class extends I{descriptor={readsExchangeTimeZone:!0,id:`mtfma`,name:`MTF Moving Average`,placement:`overlay`,defaultConfig:{period:50,timeframe:`1d`,source:`close`},shortName:`MTF MA`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`MA`,color:0}]};calculate(e,t){let n=H(t,`period`,50,1),r=String(t.params.timeframe??`1d`),i=new L,a=Array(e.length).fill(null);if(e.length===0)return{values:i,series:a};let o=[],s=Dt(e,r,t.exchangeTimeZone),c=s(e[0].time),l=e[0].close,u=null,d=()=>{if(o.length<n)return;let e=0;for(let t=o.length-n;t<o.length;t++)e+=o[t];u=e/n};for(let t=0;t<e.length;t++){let n=s(e[t].time);if(n!==c&&(o.push(l),d(),c=n),l=e[t].close,u!==null){let n={value:u};i.set(e[t].time,n),a[t]=n}}return{values:i,series:a}}},ss=class extends I{descriptor={readsExchangeTimeZone:!0,id:`svwap`,name:`Session VWAP`,placement:`overlay`,defaultConfig:{bands:1},inputs:{bands:{kind:`int`,min:0,max:3}},shortName:`SVWAP`,plots:[{key:`value`,title:`VWAP`,color:0,breakOn:`session`},{key:`u1`,title:`+1σ`,color:1,width:1,lineStyle:`dashed`,opacity:.55,breakOn:`session`},{key:`l1`,title:`−1σ`,color:1,width:1,lineStyle:`dashed`,opacity:.55,breakOn:`session`},{key:`u2`,title:`+2σ`,color:1,width:1,lineStyle:`dashed`,opacity:.55,breakOn:`session`},{key:`l2`,title:`−2σ`,color:1,width:1,lineStyle:`dashed`,opacity:.55,breakOn:`session`},{key:`u3`,title:`+3σ`,color:1,width:1,lineStyle:`dashed`,opacity:.55,breakOn:`session`},{key:`l3`,title:`−3σ`,color:1,width:1,lineStyle:`dashed`,opacity:.55,breakOn:`session`}]};calculate(e,n){let r=(0,t.barsAreDaily)(e)===!0?0:Math.min(3,H(n,`bands`,1,0)),i=new L,a=Array(e.length).fill(null);if(e.length===0)return{values:i,series:a};let o=Dt(e,`session`,n.exchangeTimeZone),s=o(e[0].time),c=0,l=0,u=0;for(let t=0;t<e.length;t++){let n=e[t],d=o(n.time);d!==s&&(c=0,l=0,u=0,s=d);let f=(n.high+n.low+n.close)/3;if(c+=f*n.volume,l+=f*f*n.volume,u+=n.volume,u>0){let e=c/u,o={value:e,session:s};if(r>0){let t=Math.max(0,l/u-e*e),n=Math.sqrt(t);for(let t=1;t<=r;t++)o[`u${t}`]=e+t*n,o[`l${t}`]=e-t*n}i.set(n.time,o),a[t]=o}}return{values:i,series:a}}},cs=class extends I{descriptor={id:`chandelier`,name:`Chandelier Exit`,placement:`overlay`,defaultConfig:{period:22,multiplier:3},inputs:{period:{kind:`int`,min:1},multiplier:{kind:`number`,min:.1,step:.1}},shortName:`CE`,plots:[{key:`long`,title:`Long`,color:0,lineStyle:`dashed`},{key:`short`,title:`Short`,color:1,lineStyle:`dashed`}]};calculate(e,t){let n=H(t,`period`,22,1),r=V(t,`multiplier`,3),i=new L,a=Array(e.length).fill(null),o=e.length;if(o<=n)return{values:i,series:a};let s=Array(o).fill(0);for(let t=1;t<o;t++){let n=e[t-1].close;s[t]=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-n),Math.abs(e[t].low-n))}let c=0;for(let e=1;e<=n;e++)c+=s[e];c/=n;for(let t=n;t<o;t++){t>n&&(c=(c*(n-1)+s[t])/n);let o=-1/0,l=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>o&&(o=e[r].high),e[r].low<l&&(l=e[r].low);let u={long:o-r*c,short:l+r*c};i.set(e[t].time,u),a[t]=u}return{values:i,series:a}}},ls=class extends I{descriptor={id:`alligator`,name:`Alligator`,placement:`overlay`,defaultConfig:{jaw:13,teeth:8,lips:5,jawShift:8,teethShift:5,lipsShift:3},inputs:{jaw:{kind:`int`,min:1},teeth:{kind:`int`,min:1},lips:{kind:`int`,min:1},jawShift:{kind:`int`,min:0},teethShift:{kind:`int`,min:0},lipsShift:{kind:`int`,min:0}},shortName:`Alligator`,plots:[{key:`jaw`,title:`Jaw`,color:0},{key:`teeth`,title:`Teeth`,color:1},{key:`lips`,title:`Lips`,color:2}]};calculate(e,t){let n=H(t,`jaw`,13,1),r=H(t,`teeth`,8,1),i=H(t,`lips`,5,1),a=H(t,`jawShift`,8,0),o=H(t,`teethShift`,5,0),s=H(t,`lipsShift`,3,0),c=new L,l=e.length,u=Array(l).fill(null);if(l===0)return{values:c,series:u};let d=e.map(e=>(e.high+e.low)/2),f=us(d,n),p=us(d,r),m=us(d,i),h=Array(l).fill(void 0),g=Array(l).fill(void 0),_=Array(l).fill(void 0);for(let e=0;e<l;e++)f[e]!==void 0&&e+a<l&&(h[e+a]=f[e]),p[e]!==void 0&&e+o<l&&(g[e+o]=p[e]),m[e]!==void 0&&e+s<l&&(_[e+s]=m[e]);for(let t=0;t<l;t++){if(h[t]===void 0&&g[t]===void 0&&_[t]===void 0)continue;let n={};h[t]!==void 0&&(n.jaw=h[t]),g[t]!==void 0&&(n.teeth=g[t]),_[t]!==void 0&&(n.lips=_[t]),c.set(e[t].time,n),u[t]=n}return{values:c,series:u}}};function us(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<t)return r;let i=0;for(let n=0;n<t;n++)i+=e[n];let a=i/t;r[t-1]=a;for(let i=t;i<n;i++)a=(a*(t-1)+e[i])/t,r[i]=a;return r}var ds=class extends I{descriptor={id:`vwma`,name:`Volume Weighted Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`VWMA`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`VWMA`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null),a=0,o=0;for(let t=0;t<e.length;t++){let s=e[t].close*e[t].volume;if(a+=s,o+=e[t].volume,t>=n){let r=e[t-n];a-=r.close*r.volume,o-=r.volume}if(t>=n-1&&o>0){let n={value:a/o};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=H(t,`period`,20,1);for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0,a=0;for(let n=t-i+1;n<=t;n++)r+=e[n].close*e[n].volume,a+=e[n].volume;this.writePoint(n,e,t,a>0?{value:r/a}:null)}return n}},fs=class extends I{descriptor={id:`wma`,name:`Weighted Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`WMA`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`WMA`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null),a=n*(n+1)/2,o=0,s=0;for(let t=0;t<e.length;t++){let c=e[t].close;if(s+=c*n-o,o+=c,t>=n&&(o-=e[t-n].close),t>=n-1){let n={value:s/a};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=H(t,`period`,20,1),a=i*(i+1)/2;for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0,o=t-i+1;for(let t=0;t<i;t++)r+=e[o+t].close*(t+1);this.writePoint(n,e,t,{value:r/a})}return n}},ps=class extends I{descriptor={id:`envelope`,name:`Moving Average Envelope`,placement:`overlay`,defaultConfig:{period:20,percent:2.5,source:`close`},shortName:`Env`,inputs:{source:{source:!0},period:{kind:`int`,min:1},percent:{kind:`number`,min:0,step:.1}},fills:[{between:[`upper`,`lower`],color:0,opacity:.08}],plots:[{key:`upper`,title:`Upper`,color:0},{key:`basis`,title:`Basis`,color:1},{key:`lower`,title:`Lower`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=V(t,`percent`,2.5)/100,i=new L,a=Array(e.length).fill(null),o=0;for(let t=0;t<e.length;t++)if(o+=e[t].close,t>=n&&(o-=e[t-n].close),t>=n-1){let s=o/n,c={basis:s,upper:s*(1+r),lower:s*(1-r)};i.set(e[t].time,c),a[t]=c}return{values:i,series:a}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=H(t,`period`,20,1),a=V(t,`percent`,2.5)/100;for(let t=r;t<e.length;t++){if(t<i-1){this.writePoint(n,e,t,null);continue}let r=0;for(let n=t-i+1;n<=t;n++)r+=e[n].close;let o=r/i;this.writePoint(n,e,t,{basis:o,upper:o*(1+a),lower:o*(1-a)})}return n}};function ms(e,t){let n=2/(t+1),r=Array(e.length).fill(null),i=0,a=0;for(let o=0;o<e.length;o++){if(o<t-1){a+=e[o];continue}i=o===t-1?(a+e[o])/t:(e[o]-i)*n+i,r[o]=i}return r}function hs(e,t,n){let r=Array(n).fill(null);for(let n=0;n<e.length;n++)e[n]!==null&&(r[t[n]]=e[n]);return r}function gs(e){let t=[],n=[];for(let r=0;r<e.length;r++)e[r]!==null&&(t.push(e[r]),n.push(r));return{values:t,indices:n}}var _s=class extends I{descriptor={id:`tema`,name:`Triple EMA`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`TEMA`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`TEMA`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null),a=ms(e.map(e=>e.close),n),o=gs(a),s=hs(ms(o.values,n),o.indices,e.length),c=gs(s),l=hs(ms(c.values,n),c.indices,e.length);for(let t=0;t<e.length;t++){let n=a[t],o=s[t],c=l[t];if(n===null||o===null||c===null)continue;let u={value:3*n-3*o+c};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}},vs=class extends I{descriptor={id:`ao`,name:`Awesome Oscillator`,placement:`panel`,defaultConfig:{fast:5,slow:34},inputs:{fast:{kind:`int`,min:1},slow:{kind:`int`,min:1}},shortName:`AO`,plots:[{key:`value`,title:`AO`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}]};calculate(e,t){let n=H(t,`fast`,5,1),r=H(t,`slow`,34,1),i=new L,a=Array(e.length).fill(null);if(e.length<r)return{values:i,series:a};let o=Array(e.length);for(let t=0;t<e.length;t++)o[t]=(e[t].high+e[t].low)/2;let s=0,c=0,l;for(let t=0;t<e.length;t++)if(c+=o[t],t>=r&&(c-=o[t-r]),s+=o[t],t>=n&&(s-=o[t-n]),t>=r-1){let o=s/n-c/r,u={value:o,up:+(l===void 0||o>=l)};i.set(e[t].time,u),a[t]=u,l=o}return{values:i,series:a}}},ys=class extends I{descriptor={id:`chaikinOsc`,name:`Chaikin Oscillator`,placement:`panel`,defaultConfig:{fast:3,slow:10},inputs:{fast:{kind:`int`,min:1},slow:{kind:`int`,min:1}},shortName:`Chaikin Osc`,plots:[{key:`value`,title:`Chaikin`,color:0,kind:`histogram`,tone:`sign`,downColor:1}]};calculate(e,t){let n=H(t,`fast`,3,1),r=H(t,`slow`,10,1),i=new L,a=Array(e.length).fill(null);if(e.length<r)return{values:i,series:a};let o=2/(n+1),s=2/(r+1),c=0,l=0,u=0;for(let t=0;t<e.length;t++){let{high:n,low:d,close:f,volume:p}=e[t],m=n-d,h=m===0?0:(f-d-(n-f))/m;if(c+=h*p,t===0?(l=c,u=c):(l=(c-l)*o+l,u=(c-u)*s+u),t>=r-1){let n={value:l-u,adl:c};i.set(e[t].time,n),a[t]=n}}return{values:i,series:a}}},bs=class extends I{descriptor={id:`rsi`,name:`Relative Strength Index`,placement:`panel`,defaultConfig:{period:14,source:`close`},shortName:`RSI`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`RSI`,color:0}],scale:{min:0,max:100},levels:[30,70]};smoothing=new WeakMap;workerState(e){return this.smoothing.get(e)}adoptWorkerState(e,t){t&&this.smoothing.set(e,t)}calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null),a={values:r,series:i};if(e.length<n+1)return a;let o=[],s=[],c=0,l=0;for(let t=1;t<=n;t++){let n=e[t].close-e[t-1].close;n>0?c+=n:l-=n}c/=n,l/=n,o[n]=c,s[n]=l;let u={value:l===0?100:100-100/(1+c/l)};r.set(e[n].time,u),i[n]=u;for(let t=n+1;t<e.length;t++){let a=e[t].close-e[t-1].close,u=a>0?a:0,d=a<0?-a:0;c=(c*(n-1)+u)/n,l=(l*(n-1)+d)/n,o[t]=c,s[t]=l;let f={value:l===0?100:100-100/(1+c/l)};r.set(e[t].time,f),i[t]=f}return this.smoothing.set(a,{gain:o,loss:s}),a}update(e,t,n,r){let i=H(t,`period`,14,1),a=this.smoothing.get(n);if(!a||r<=i||!this.canResume(e,n,r))return null;let o=a.gain[r-1],s=a.loss[r-1];if(o===void 0||s===void 0)return null;for(let t=r;t<e.length;t++){let r=e[t].close-e[t-1].close,c=r>0?r:0,l=r<0?-r:0;o=(o*(i-1)+c)/i,s=(s*(i-1)+l)/i,a.gain[t]=o,a.loss[t]=s;let u=s===0?100:100-100/(1+o/s);this.writePoint(n,e,t,{value:u})}return n}},xs=class extends I{descriptor={id:`macd`,name:`MACD`,placement:`panel`,defaultConfig:{fast:12,slow:26,signal:9,source:`close`},shortName:`MACD`,inputs:{source:{source:!0},fast:{kind:`int`,min:1},slow:{kind:`int`,min:1},signal:{kind:`int`,min:1}},plots:[{key:`histogram`,title:`Histogram`,color:2,kind:`histogram`,tone:`sign`,downColor:3},{key:`macd`,title:`MACD`,color:0},{key:`signal`,title:`Signal`,color:1}]};emas=new WeakMap;workerState(e){return this.emas.get(e)}adoptWorkerState(e,t){t&&this.emas.set(e,t)}calculate(e,t){let n=H(t,`fast`,12,1),r=H(t,`slow`,26,1),i=H(t,`signal`,9,1),a=new L,o=Array(e.length).fill(null),s={values:a,series:o};if(e.length<r)return s;let c=2/(n+1),l=2/(r+1),u=2/(i+1),d=Array(e.length),f=Array(e.length),p=e[0].close,m=e[0].close,h=0,g=!1;for(let t=0;t<e.length;t++){let n=e[t].close;if(t===0?(p=n,m=n):(p=(n-p)*c+p,m=(n-m)*l+m),d[t]=p,f[t]=m,t>=r-1){let n=p-m;g?h=(n-h)*u+h:(h=n,g=!0);let r=n-h,i={macd:n,signal:h,histogram:r};a.set(e[t].time,i),o[t]=i}}return this.emas.set(s,{fast:d,slow:f}),s}update(e,t,n,r){let i=H(t,`fast`,12,1),a=H(t,`slow`,26,1),o=H(t,`signal`,9,1),s=this.emas.get(n);if(!s||r<a||!this.canResume(e,n,r))return null;let c=s.fast[r-1],l=s.slow[r-1],u=n.series[r-1]?.signal;if(c===void 0||l===void 0||u===void 0)return null;let d=2/(i+1),f=2/(a+1),p=2/(o+1);for(let t=r;t<e.length;t++){let r=e[t].close;c=(r-c)*d+c,l=(r-l)*f+l,s.fast[t]=c,s.slow[t]=l;let i=c-l;u=(i-u)*p+u,this.writePoint(n,e,t,{macd:i,signal:u,histogram:i-u})}return n}},Ss=class extends I{descriptor={id:`stochastic`,name:`Stochastic Oscillator`,placement:`panel`,defaultConfig:{kPeriod:14,dPeriod:3,smooth:3},inputs:{kPeriod:{kind:`int`,min:1},dPeriod:{kind:`int`,min:1},smooth:{kind:`int`,min:1}},shortName:`Stoch`,plots:[{key:`k`,title:`%K`,color:0},{key:`d`,title:`%D`,color:1}],scale:{min:0,max:100},levels:[20,80]};calculate(e,t){let n=H(t,`kPeriod`,14,1),r=H(t,`dPeriod`,3,1),i=H(t,`smooth`,3,1),a=new L,o=Array(e.length).fill(null);if(e.length<n)return{values:a,series:o};let s=[];for(let t=0;t<e.length;t++){if(t<n-1){s.push(0);continue}let r=-1/0,i=1/0;for(let a=t-n+1;a<=t;a++)e[a].high>r&&(r=e[a].high),e[a].low<i&&(i=e[a].low);s.push(r===i?50:(e[t].close-i)/(r-i)*100)}let c=[];for(let e=0;e<s.length;e++){if(e<n-1+i-1){c.push(0);continue}let t=0;for(let n=e-i+1;n<=e;n++)t+=s[n];c.push(t/i)}let l=n-1+i-1;for(let t=l;t<c.length;t++){let n={k:c[t]};if(t>=l+r-1){let e=0;for(let n=t-r+1;n<=t;n++)e+=c[n];n.d=e/r}a.set(e[t].time,n),o[t]=n}return{values:a,series:o}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=H(t,`kPeriod`,14,1),a=H(t,`dPeriod`,3,1),o=H(t,`smooth`,3,1),s=i-1+o-1,c=t=>{let n=-1/0,r=1/0;for(let a=t-i+1;a<=t;a++)e[a].high>n&&(n=e[a].high),e[a].low<r&&(r=e[a].low);return n===r?50:(e[t].close-r)/(n-r)*100},l=e=>{let t=0;for(let n=e-o+1;n<=e;n++)t+=c(n);return t/o};for(let t=r;t<e.length;t++){if(t<s||e.length<i){this.writePoint(n,e,t,null);continue}let r={k:l(t)};if(t>=s+a-1){let e=0;for(let n=t-a+1;n<=t;n++)e+=l(n);r.d=e/a}this.writePoint(n,e,t,r)}return n}},Cs=class extends I{descriptor={id:`atr`,name:`Average True Range`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`ATR`,plots:[{key:`value`,title:`ATR`,color:0}]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null);if(e.length<Math.max(2,n))return{values:r,series:i};let a=[e[0].high-e[0].low];for(let t=1;t<e.length;t++){let n=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a.push(n)}let o=0;for(let e=0;e<n;e++)o+=a[e];o/=n;let s={value:o};r.set(e[n-1].time,s),i[n-1]=s;for(let t=n;t<e.length;t++){o=(o*(n-1)+a[t])/n;let s={value:o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}update(e,t,n,r){let i=H(t,`period`,14,1);if(r<i||!this.canResume(e,n,r))return null;let a=n.series[r-1]?.value;if(a===void 0)return null;for(let t=r;t<e.length;t++){let r=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a=(a*(i-1)+r)/i,this.writePoint(n,e,t,{value:a})}return n}},ws=class extends I{descriptor={id:`adx`,name:`Average Directional Index`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`ADX`,plots:[{key:`adx`,title:`ADX`,color:0},{key:`plusDI`,title:`+DI`,color:1},{key:`minusDI`,title:`−DI`,color:2}],scale:{min:0}};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null);if(e.length<n*2)return{values:r,series:i};let a=[],o=[],s=[];for(let t=1;t<e.length;t++){let n=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-e[t-1].close),Math.abs(e[t].low-e[t-1].close));a.push(n);let r=e[t].high-e[t-1].high,i=e[t-1].low-e[t].low;o.push(r>i&&r>0?r:0),s.push(i>r&&i>0?i:0)}let c=0,l=0,u=0;for(let e=0;e<n;e++)c+=a[e],l+=o[e],u+=s[e];let d=[];for(let t=n;t<a.length;t++){t>n&&(c=c-c/n+a[t],l=l-l/n+o[t],u=u-u/n+s[t]);let f=c===0?0:l/c*100,p=c===0?0:u/c*100,m=f+p,h=m===0?0:Math.abs(f-p)/m*100;d.push(h);let g=t+1,_={plusDI:f,minusDI:p,dx:h};r.set(e[g].time,_),i[g]=_}if(d.length>=n){let t=0;for(let e=0;e<n;e++)t+=d[e];t/=n;let a=n*2;if(a<e.length){let n=r.get(e[a].time);n&&(n.adx=t),i[a]&&(i[a].adx=t)}for(let a=n;a<d.length;a++){t=(t*(n-1)+d[a])/n;let o=a+n+1;if(o<e.length){let n=r.get(e[o].time);n&&(n.adx=t),i[o]&&(i[o].adx=t)}}}return{values:r,series:i}}},Ts=class extends I{descriptor={id:`obv`,name:`On Balance Volume`,placement:`panel`,defaultConfig:{},shortName:`OBV`,plots:[{key:`value`,title:`OBV`,color:0}]};calculate(e,t){let n=new L,r=Array(e.length).fill(null);if(e.length===0)return{values:n,series:r};let i=0,a={value:i};n.set(e[0].time,a),r[0]=a;for(let t=1;t<e.length;t++){e[t].close>e[t-1].close?i+=e[t].volume:e[t].close<e[t-1].close&&(i-=e[t].volume);let a={value:i};n.set(e[t].time,a),r[t]=a}return{values:n,series:r}}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=n.series[r-1]?.value;if(i===void 0)return null;for(let t=r;t<e.length;t++)e[t].close>e[t-1].close?i+=e[t].volume:e[t].close<e[t-1].close&&(i-=e[t].volume),this.writePoint(n,e,t,{value:i});return n}},Es=class extends I{descriptor={id:`williamsR`,name:`Williams %R`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`%R`,plots:[{key:`value`,title:`%R`,color:0}],scale:{min:-100,max:0},levels:[-80,-20]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=-1/0,o=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<o&&(o=e[r].low);let s={value:a===o?-50:(a-e[t].close)/(a-o)*-100};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}},Ds=class extends I{descriptor={id:`cci`,name:`Commodity Channel Index`,placement:`panel`,defaultConfig:{period:20},inputs:{period:{kind:`int`,min:1}},shortName:`CCI`,plots:[{key:`value`,title:`CCI`,color:0}],levels:[-100,0,100]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0;for(let r=t-n+1;r<=t;r++)a+=(e[r].high+e[r].low+e[r].close)/3;let o=a/n,s=0;for(let r=t-n+1;r<=t;r++){let t=(e[r].high+e[r].low+e[r].close)/3;s+=Math.abs(t-o)}let c=s/n,l=(e[t].high+e[t].low+e[t].close)/3,u={value:c===0?0:(l-o)/(.015*c)};r.set(e[t].time,u),i[t]=u}return{values:r,series:i}}},Os=class extends I{descriptor={id:`mfi`,name:`Money Flow Index`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`MFI`,plots:[{key:`value`,title:`MFI`,color:0}],scale:{min:0,max:100},levels:[20,80]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null);if(e.length<n+1)return{values:r,series:i};let a=e.map(e=>(e.high+e.low+e.close)/3),o=a.map((t,n)=>t*e[n].volume);for(let t=n;t<e.length;t++){let s=0,c=0;for(let e=t-n+1;e<=t;e++)a[e]>a[e-1]?s+=o[e]:a[e]<a[e-1]&&(c+=o[e]);let l={value:c===0?100:100-100/(1+s/c)};r.set(e[t].time,l),i[t]=l}return{values:r,series:i}}},ks=class extends I{descriptor={id:`aroon`,name:`Aroon`,placement:`panel`,defaultConfig:{period:25},inputs:{period:{kind:`int`,min:1}},shortName:`Aroon`,plots:[{key:`up`,title:`Up`,color:0},{key:`down`,title:`Down`,color:1}],scale:{min:0,max:100}};calculate(e,t){let n=H(t,`period`,25,1),r=new L,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=0,o=0,s=-1/0,c=1/0;for(let r=0;r<=n;r++){let i=t-n+r;e[i].high>s&&(s=e[i].high,a=r),e[i].low<c&&(c=e[i].low,o=r)}let l={up:a/n*100,down:o/n*100};r.set(e[t].time,l),i[t]=l}return{values:r,series:i}}},As=class extends I{descriptor={id:`roc`,name:`Rate of Change`,placement:`panel`,defaultConfig:{period:12,source:`close`},shortName:`ROC`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`ROC`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`period`,12,1),r=new L,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=e[t-n].close,o={value:a===0?0:(e[t].close-a)/a*100};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}},js=class extends I{descriptor={id:`tsi`,name:`True Strength Index`,placement:`panel`,defaultConfig:{longPeriod:25,shortPeriod:13,signalPeriod:7,source:`close`},shortName:`TSI`,inputs:{source:{source:!0},longPeriod:{kind:`int`,min:1},shortPeriod:{kind:`int`,min:1},signalPeriod:{kind:`int`,min:1}},plots:[{key:`tsi`,title:`TSI`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};emaSmooth(e,t){let n=2/(t+1),r=[e[0]];for(let t=1;t<e.length;t++)r.push((e[t]-r[t-1])*n+r[t-1]);return r}calculate(e,t){let n=H(t,`longPeriod`,25,1),r=H(t,`shortPeriod`,13,1),i=H(t,`signalPeriod`,7,1),a=new L,o=Array(e.length).fill(null);if(e.length<2)return{values:a,series:o};let s=[],c=[];for(let t=1;t<e.length;t++){let n=e[t].close-e[t-1].close;s.push(n),c.push(Math.abs(n))}let l=this.emaSmooth(this.emaSmooth(s,n),r),u=this.emaSmooth(this.emaSmooth(c,n),r),d=[];for(let e=0;e<l.length;e++)d.push(u[e]===0?0:l[e]/u[e]*100);let f=this.emaSmooth(d,i);for(let t=0;t<d.length;t++){let n=t+1;if(n<e.length){let r={tsi:d[t],signal:f[t]};a.set(e[n].time,r),o[n]=r}}return{values:a,series:o}}},Ms=class extends I{descriptor={id:`cmf`,name:`Chaikin Money Flow`,placement:`panel`,defaultConfig:{period:20},inputs:{period:{kind:`int`,min:1}},shortName:`CMF`,plots:[{key:`value`,title:`CMF`,color:0,kind:`histogram`,tone:`sign`,downColor:1}]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0,o=0;for(let r=t-n+1;r<=t;r++){let t=e[r].high-e[r].low,n=t===0?0:(e[r].close-e[r].low-(e[r].high-e[r].close))/t;a+=n*e[r].volume,o+=e[r].volume}let s={value:o===0?0:a/o};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}},Ns=class extends I{descriptor={id:`voldelta`,name:`Volume Delta`,placement:`panel`,defaultConfig:{mode:0},inputs:{mode:{kind:`int`,min:0,max:1}},shortName:`Vol Δ`,plots:[{key:`value`,title:`Delta`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}]};calculate(e,t){let n=V(t,`mode`,0)>=1,r=new L,i=Array(e.length).fill(null),a=0;for(let t=0;t<e.length;t++){let o=e[t],s=o.close>=o.open,c=s?o.volume:-o.volume;a+=c;let l={value:n?a:c,up:+!!s};r.set(o.time,l),i[t]=l}return{values:r,series:i}}},Ps=class extends I{descriptor={id:`vortex`,name:`Vortex Indicator`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`VI`,plots:[{key:`viPlus`,title:`VI+`,color:0},{key:`viMinus`,title:`VI−`,color:1}],levels:[1]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};let a=Array(e.length).fill(0),o=Array(e.length).fill(0),s=Array(e.length).fill(0);for(let t=1;t<e.length;t++){a[t]=Math.abs(e[t].high-e[t-1].low),o[t]=Math.abs(e[t].low-e[t-1].high);let n=e[t].high,r=e[t].low,i=e[t-1].close;s[t]=Math.max(n-r,Math.abs(n-i),Math.abs(r-i))}let c=0,l=0,u=0;for(let t=1;t<e.length;t++)if(c+=a[t],l+=o[t],u+=s[t],t>n&&(c-=a[t-n],l-=o[t-n],u-=s[t-n]),t>=n&&u>0){let n={viPlus:c/u,viMinus:l/u};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}},Fs=class extends I{descriptor={id:`chop`,name:`Choppiness Index`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:2}},shortName:`CHOP`,plots:[{key:`value`,title:`CHOP`,color:0}],scale:{min:0,max:100},levels:[38.2,61.8]};calculate(e,t){let n=H(t,`period`,14,2),r=new L,i=Array(e.length).fill(null);if(e.length<=n)return{values:r,series:i};let a=Array(e.length).fill(0);for(let t=1;t<e.length;t++){let n=e[t].high,r=e[t].low,i=e[t-1].close;a[t]=Math.max(n-r,Math.abs(n-i),Math.abs(r-i))}let o=Math.log10(n),s=0;for(let t=1;t<e.length;t++)if(s+=a[t],t>n&&(s-=a[t-n]),t>=n){let a=-1/0,c=1/0;for(let r=t-n+1;r<=t;r++)e[r].high>a&&(a=e[r].high),e[r].low<c&&(c=e[r].low);let l=a-c;if(l>0&&s>0){let n={value:Math.max(0,Math.min(100,100*Math.log10(s/l)/o))};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}},Is=class extends I{descriptor={id:`uo`,name:`Ultimate Oscillator`,placement:`panel`,defaultConfig:{fast:7,mid:14,slow:28},inputs:{fast:{kind:`int`,min:1},mid:{kind:`int`,min:1},slow:{kind:`int`,min:1}},shortName:`UO`,plots:[{key:`value`,title:`UO`,color:0}],scale:{min:0,max:100},levels:[30,70]};calculate(e,t){let n=H(t,`fast`,7,1),r=H(t,`mid`,14,1),i=H(t,`slow`,28,1),a=new L,o=Array(e.length).fill(null);if(e.length<=i)return{values:a,series:o};let s=Array(e.length).fill(0),c=Array(e.length).fill(0);for(let t=1;t<e.length;t++){let n=e[t-1].close,r=Math.min(e[t].low,n),i=Math.max(e[t].high,n);s[t]=e[t].close-r,c[t]=i-r}let l=(e,t,n)=>{let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i];return r};for(let t=i;t<e.length;t++){let u=Ls(l(s,t,n),l(c,t,n)),d=Ls(l(s,t,r),l(c,t,r)),f=Ls(l(s,t,i),l(c,t,i)),p={value:100*(4*u+2*d+f)/7};a.set(e[t].time,p),o[t]=p}return{values:a,series:o}}};function Ls(e,t){return t===0?0:e/t}var Rs=class extends I{descriptor={id:`fi`,name:`Force Index`,placement:`panel`,defaultConfig:{period:13},inputs:{period:{kind:`int`,min:1}},shortName:`EFI`,plots:[{key:`value`,title:`EFI`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`period`,13,1),r=new L,i=Array(e.length).fill(null);if(e.length<2)return{values:r,series:i};let a=2/(n+1),o;for(let t=1;t<e.length;t++){let s=(e[t].close-e[t-1].close)*e[t].volume;if(o=o===void 0?s:s*a+o*(1-a),t>=n){let n={value:o};r.set(e[t].time,n),i[t]=n}}return{values:r,series:i}}},zs=class extends I{descriptor={id:`crsi`,name:`Connors RSI`,placement:`panel`,defaultConfig:{rsiPeriod:3,streakPeriod:2,rankPeriod:100,source:`close`},shortName:`CRSI`,inputs:{source:{source:!0},rsiPeriod:{kind:`int`,min:1},streakPeriod:{kind:`int`,min:1},rankPeriod:{kind:`int`,min:1}},plots:[{key:`value`,title:`CRSI`,color:0}],scale:{min:0,max:100},levels:[10,90]};calculate(e,t){let n=H(t,`rsiPeriod`,3,1),r=H(t,`streakPeriod`,2,1),i=H(t,`rankPeriod`,100,1),a=new L,o=Array(e.length).fill(null),s=e.length;if(s<2)return{values:a,series:o};let c=e.map(e=>e.close),l=Bs(c,n),u=Array(s).fill(0);for(let e=1;e<s;e++)c[e]>c[e-1]?u[e]=u[e-1]>0?u[e-1]+1:1:c[e]<c[e-1]?u[e]=u[e-1]<0?u[e-1]-1:-1:u[e]=0;let d=Bs(u,r),f=Array(s).fill(0);for(let e=1;e<s;e++)f[e]=c[e-1]===0?0:(c[e]-c[e-1])/c[e-1]*100;for(let t=0;t<s;t++){if(t<i+1)continue;let n=l[t],r=d[t];if(n===void 0||r===void 0)continue;let s=0;for(let e=t-i;e<t;e++)f[e]<f[t]&&s++;let c=s/i*100,u={value:(n+r+c)/3};a.set(e[t].time,u),o[t]=u}return{values:a,series:o}}};function Bs(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<=t)return r;let i=0,a=0;for(let n=1;n<=t;n++){let t=e[n]-e[n-1];t>=0?i+=t:a-=t}i/=t,a/=t,r[t]=a===0?100:100-100/(1+i/a);for(let o=t+1;o<n;o++){let n=e[o]-e[o-1],s=n>0?n:0,c=n<0?-n:0;i=(i*(t-1)+s)/t,a=(a*(t-1)+c)/t,r[o]=a===0?100:100-100/(1+i/a)}return r}var Vs=class extends I{descriptor={id:`coppock`,name:`Coppock Curve`,placement:`panel`,defaultConfig:{longRoc:14,shortRoc:11,wma:10,source:`close`},shortName:`Coppock`,inputs:{source:{source:!0},longRoc:{kind:`int`,min:1},shortRoc:{kind:`int`,min:1},wma:{kind:`int`,min:1}},plots:[{key:`value`,title:`Coppock`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`longRoc`,14,1),r=H(t,`shortRoc`,11,1),i=H(t,`wma`,10,1),a=new L,o=Array(e.length).fill(null),s=e.length,c=Math.max(n,r);if(s<=c+i)return{values:a,series:o};let l=e.map(e=>e.close),u=(e,t)=>l[e-t]===0?0:(l[e]-l[e-t])/l[e-t]*100,d=Array(s).fill(void 0);for(let e=c;e<s;e++)d[e]=u(e,n)+u(e,r);let f=i*(i+1)/2;for(let t=c+i-1;t<s;t++){let n=0,r=!0;for(let e=0;e<i;e++){let a=d[t-e];if(a===void 0){r=!1;break}n+=a*(i-e)}if(!r)continue;let s={value:n/f};a.set(e[t].time,s),o[t]=s}return{values:a,series:o}}},Hs=class extends I{descriptor={id:`kst`,name:`Know Sure Thing`,placement:`panel`,defaultConfig:{roc1:10,roc2:15,roc3:20,roc4:30,sma1:10,sma2:10,sma3:10,sma4:15,signal:9,source:`close`},shortName:`KST`,inputs:{source:{source:!0},roc1:{kind:`int`,min:1},roc2:{kind:`int`,min:1},roc3:{kind:`int`,min:1},roc4:{kind:`int`,min:1},sma1:{kind:`int`,min:1},sma2:{kind:`int`,min:1},sma3:{kind:`int`,min:1},sma4:{kind:`int`,min:1},signal:{kind:`int`,min:1}},plots:[{key:`value`,title:`KST`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=H(t,`roc1`,10,1),r=H(t,`roc2`,15,1),i=H(t,`roc3`,20,1),a=H(t,`roc4`,30,1),o=H(t,`sma1`,10,1),s=H(t,`sma2`,10,1),c=H(t,`sma3`,10,1),l=H(t,`sma4`,15,1),u=H(t,`signal`,9,1),d=new L,f=Array(e.length).fill(null),p=e.length;if(p<2)return{values:d,series:f};let m=e.map(e=>e.close),h=Ws(Us(m,n),o),g=Ws(Us(m,r),s),_=Ws(Us(m,i),c),v=Ws(Us(m,a),l),y=Array(p).fill(void 0);for(let e=0;e<p;e++)h[e]===void 0||g[e]===void 0||_[e]===void 0||v[e]===void 0||(y[e]=h[e]*1+g[e]*2+_[e]*3+v[e]*4);let b=Ws(y,u);for(let t=0;t<p;t++){if(y[t]===void 0)continue;let n={value:y[t]};b[t]!==void 0&&(n.signal=b[t]),d.set(e[t].time,n),f[t]=n}return{values:d,series:f}}};function Us(e,t){let n=Array(e.length).fill(void 0);for(let r=t;r<e.length;r++)n[r]=e[r-t]===0?0:(e[r]-e[r-t])/e[r-t]*100;return n}function Ws(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=!0;for(let n=r-t+1;n<=r;n++){let t=e[n];if(t===void 0){a=!1;break}i+=t}a&&(n[r]=i/t)}return n}var Gs=class extends I{descriptor={id:`elderray`,name:`Elder Ray`,placement:`panel`,defaultConfig:{period:13},inputs:{period:{kind:`int`,min:1}},shortName:`Elder Ray`,plots:[{key:`bull`,title:`Bull`,color:0,kind:`histogram`},{key:`bear`,title:`Bear`,color:1,kind:`histogram`}]};calculate(e,t){let n=H(t,`period`,13,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a===0)return{values:r,series:i};let o=2/(n+1),s;for(let t=0;t<a;t++)if(s=s===void 0?e[t].close:e[t].close*o+s*(1-o),t>=n-1){let n={bull:e[t].high-s,bear:e[t].low-s};r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}render(t,n,r,i){let a=n.series;if(!a)return;let o=Math.max(0,r.visibleRange.from),s=Math.min(r.visibleRange.to,a.length-1),c=e.E(r),l=c(0),u=Math.max(1,r.barWidth/2),d=[[`bull`,i.colors[0],-u],[`bear`,i.colors[1]??i.colors[0],0]];for(let[n,f,p]of d)if(i.plots?.[n]?.visible!==!1){t.beginPath(),t.fillStyle=f;for(let i=o;i<=s;i++){let o=a[i]?.[n];if(o===void 0||!Number.isFinite(o))continue;let s=c(o);t.rect(e.b(i,r)+p,Math.min(s,l),u,Math.max(1,Math.abs(s-l)))}t.fill()}}},Ks=class extends I{descriptor={id:`stc`,name:`Schaff Trend Cycle`,placement:`panel`,defaultConfig:{fast:23,slow:50,cycle:10,source:`close`},shortName:`STC`,inputs:{source:{source:!0},fast:{kind:`int`,min:1},slow:{kind:`int`,min:1},cycle:{kind:`int`,min:1}},plots:[{key:`value`,title:`STC`,color:0}],scale:{min:0,max:100},levels:[25,75]};calculate(e,t){let n=H(t,`fast`,23,1),r=H(t,`slow`,50,1),i=H(t,`cycle`,10,1),a=new L,o=Array(e.length).fill(null),s=e.length;if(s===0)return{values:a,series:o};let c=e.map(e=>e.close),l=2/(n+1),u=2/(r+1),d=c[0],f=c[0],p=Array(s);for(let e=0;e<s;e++)d=e===0?c[0]:c[e]*l+d*(1-l),f=e===0?c[0]:c[e]*u+f*(1-u),p[e]=d-f;let m=qs(qs(p,i),i);for(let t=0;t<s;t++){let n=m[t];if(n===void 0)continue;let r={value:Math.max(0,Math.min(100,n))};a.set(e[t].time,r),o[t]=r}return{values:a,series:o}}};function qs(e,t){let n=e.length,r=Array(n).fill(void 0),i;for(let a=0;a<n;a++){if(a<t-1)continue;let n=1/0,o=-1/0,s=!0;for(let r=a-t+1;r<=a;r++){let t=e[r];if(t===void 0){s=!1;break}t<n&&(n=t),t>o&&(o=t)}if(!s||e[a]===void 0)continue;let c=o-n>0?(e[a]-n)/(o-n)*100:50;i=i===void 0?c:i+.5*(c-i),r[a]=i}return r}var Js=class extends I{descriptor={id:`kvo`,name:`Klinger Oscillator`,placement:`panel`,defaultConfig:{fast:34,slow:55,signal:13},inputs:{fast:{kind:`int`,min:1},slow:{kind:`int`,min:1},signal:{kind:`int`,min:1}},shortName:`KVO`,plots:[{key:`value`,title:`KVO`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=H(t,`fast`,34,1),r=H(t,`slow`,55,1),i=H(t,`signal`,13,1),a=new L,o=Array(e.length).fill(null),s=e.length;if(s<2)return{values:a,series:o};let c=2/(n+1),l=2/(r+1),u=2/(i+1),d,f=1,p=0,m=0,h,g,_;for(let t=0;t<s;t++){let n=e[t],i=n.high+n.low+n.close,s=d===void 0||i>d?1:-1,v=n.high-n.low;m=d===void 0?v:s===f?m+v:p+v;let y=m===0?0:n.volume*Math.abs(2*(v/m-1))*s*100;h=h===void 0?y:y*c+h*(1-c),g=g===void 0?y:y*l+g*(1-l);let b=h-g;if(_=_===void 0?b:b*u+_*(1-u),d=i,f=s,p=v,t>=r){let e={value:b,signal:_};a.set(n.time,e),o[t]=e}}return{values:a,series:o}}},Ys=class extends I{descriptor={id:`fisher`,name:`Fisher Transform`,placement:`panel`,defaultConfig:{period:9},inputs:{period:{kind:`int`,min:1}},shortName:`Fisher`,plots:[{key:`value`,title:`Fisher`,color:0},{key:`trigger`,title:`Trigger`,color:1}],levels:[0]};calculate(e,t){let n=H(t,`period`,9,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=e.map(e=>(e.high+e.low)/2),s=0,c=0;for(let t=n-1;t<a;t++){let a=-1/0,l=1/0;for(let e=t-n+1;e<=t;e++)o[e]>a&&(a=o[e]),o[e]<l&&(l=o[e]);s=.33*(a-l>0?2*(o[t]-l)/(a-l)-1:0)+.67*s,s=Math.max(-.999,Math.min(.999,s));let u=c;c=.5*Math.log((1+s)/(1-s))+.5*c;let d={value:c,trigger:u};r.set(e[t].time,d),i[t]=d}return{values:r,series:i}}},Xs=class extends I{descriptor={id:`dpo`,name:`Detrended Price Oscillator`,placement:`panel`,defaultConfig:{period:20,source:`close`},shortName:`DPO`,inputs:{source:{source:!0},period:{kind:`int`,min:2}},plots:[{key:`value`,title:`DPO`,color:0,kind:`histogram`,tone:`sign`,downColor:1}]};calculate(e,t){let n=H(t,`period`,20,2),r=Math.floor(n/2)+1,i=new L,a=Array(e.length).fill(null),o=e.length;if(o<n)return{values:i,series:a};let s=0;for(let t=0;t<o;t++)if(s+=e[t].close,t>=n&&(s-=e[t-n].close),t>=n-1&&t-r>=0){let o=s/n,c={value:e[t-r].close-o};i.set(e[t].time,c),a[t]=c}return{values:i,series:a}}},Zs=class extends I{descriptor={id:`bop`,name:`Balance of Power`,placement:`panel`,defaultConfig:{smooth:14},inputs:{smooth:{kind:`int`,min:1}},shortName:`BOP`,plots:[{key:`value`,title:`BOP`,color:0}],scale:{min:-1,max:1},levels:[0]};calculate(e,t){let n=H(t,`smooth`,14,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a===0)return{values:r,series:i};let o=Array(a);for(let t=0;t<a;t++){let n=e[t].high-e[t].low;o[t]=n>0?(e[t].close-e[t].open)/n:0}let s=0;for(let t=0;t<a;t++)if(s+=o[t],t>=n&&(s-=o[t-n]),t>=n-1){let a={value:s/n};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}},Qs=class extends I{descriptor={id:`massindex`,name:`Mass Index`,placement:`panel`,defaultConfig:{ema:9,sum:25},inputs:{ema:{kind:`int`,min:1},sum:{kind:`int`,min:1}},shortName:`Mass`,plots:[{key:`value`,title:`Mass`,color:0}],levels:[26.5,27]};calculate(e,t){let n=H(t,`ema`,9,1),r=H(t,`sum`,25,1),i=new L,a=Array(e.length).fill(null),o=e.length;if(o<r)return{values:i,series:a};let s=2/(n+1),c,l,u=Array(o).fill(0);for(let t=0;t<o;t++){let n=e[t].high-e[t].low;c=c===void 0?n:n*s+c*(1-s),l=l===void 0?c:c*s+l*(1-s),u[t]=l===0?1:c/l}let d=0;for(let t=0;t<o;t++)if(d+=u[t],t>=r&&(d-=u[t-r]),t>=n+r){let n={value:d};i.set(e[t].time,n),a[t]=n}return{values:i,series:a}}},$s=class extends I{descriptor={id:`cmo`,name:`Chande Momentum`,placement:`panel`,defaultConfig:{period:9,source:`close`},shortName:`CMO`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`CMO`,color:0}],scale:{min:-100,max:100},levels:[-50,0,50]};calculate(e,t){let n=H(t,`period`,9,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a<=n)return{values:r,series:i};let o=Array(a).fill(0),s=Array(a).fill(0);for(let t=1;t<a;t++){let n=e[t].close-e[t-1].close;o[t]=n>0?n:0,s[t]=n<0?-n:0}let c=0,l=0;for(let t=1;t<a;t++)if(c+=o[t],l+=s[t],t>n&&(c-=o[t-n],l-=s[t-n]),t>=n){let n=c+l,a={value:n>0?100*(c-l)/n:0};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}},ec=class extends I{descriptor={id:`trix`,name:`TRIX`,placement:`panel`,defaultConfig:{period:15,signal:9,source:`close`},shortName:`TRIX`,inputs:{source:{source:!0},period:{kind:`int`,min:1},signal:{kind:`int`,min:1}},plots:[{key:`value`,title:`TRIX`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=H(t,`period`,15,1),r=H(t,`signal`,9,1),i=new L,a=Array(e.length).fill(null),o=e.length;if(o<2)return{values:i,series:a};let s=tc(tc(tc(e.map(e=>e.close),n),n),n),c=Array(o).fill(0);for(let e=1;e<o;e++)c[e]=s[e-1]===0?0:(s[e]-s[e-1])/s[e-1]*100;let l=tc(c,r),u=3*n;for(let t=u;t<o;t++){let n={value:c[t],signal:l[t]};i.set(e[t].time,n),a[t]=n}return{values:i,series:a}}};function tc(e,t){let n=2/(t+1),r=Array(e.length).fill(0),i=e[0]??0;r[0]=i;for(let t=1;t<e.length;t++)i=e[t]*n+i*(1-n),r[t]=i;return r}var nc=class extends I{descriptor={id:`emv`,name:`Ease of Movement`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`EOM`,plots:[{key:`value`,title:`EOM`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a<2)return{values:r,series:i};let o=Array(a).fill(0);for(let t=1;t<a;t++){let n=(e[t].high+e[t].low)/2,r=(e[t-1].high+e[t-1].low)/2,i=e[t].high-e[t].low,a=e[t].volume;o[t]=a>0?(n-r)*i/a:0}let s=0;for(let t=1;t<a;t++)if(s+=o[t],t>n&&(s-=o[t-n]),t>=n){let a={value:s/n};r.set(e[t].time,a),i[t]=a}return{values:r,series:i}}},rc=class extends I{descriptor={id:`pvt`,name:`Price Volume Trend`,placement:`panel`,defaultConfig:{},shortName:`PVT`,plots:[{key:`value`,title:`PVT`,color:0}]};calculate(e,t){let n=new L,r=Array(e.length).fill(null),i=e.length;if(i===0)return{values:n,series:r};let a=0;n.set(e[0].time,{value:0}),r[0]={value:0};for(let t=1;t<i;t++){let i=e[t-1].close;i!==0&&(a+=e[t].volume*(e[t].close-i)/i);let o={value:a};n.set(e[t].time,o),r[t]=o}return{values:n,series:r}}},ic=class extends I{descriptor={id:`wad`,name:`Williams A/D`,placement:`panel`,defaultConfig:{},shortName:`WAD`,plots:[{key:`value`,title:`WAD`,color:0}]};calculate(e,t){let n=new L,r=Array(e.length).fill(null),i=e.length;if(i===0)return{values:n,series:r};let a=0;n.set(e[0].time,{value:0}),r[0]={value:0};for(let t=1;t<i;t++){let i=e[t-1].close,o=e[t].close;o>i?a+=o-Math.min(e[t].low,i):o<i&&(a+=o-Math.max(e[t].high,i));let s={value:a};n.set(e[t].time,s),r[t]=s}return{values:n,series:r}}},ac=class extends I{descriptor={id:`chaikinvol`,name:`Chaikin Volatility`,placement:`panel`,defaultConfig:{ema:10,roc:10},inputs:{ema:{kind:`int`,min:1},roc:{kind:`int`,min:1}},shortName:`CV`,plots:[{key:`value`,title:`CV`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`ema`,10,1),r=H(t,`roc`,10,1),i=new L,a=Array(e.length).fill(null),o=e.length;if(o<=r)return{values:i,series:a};let s=2/(n+1),c=Array(o),l=e[0].high-e[0].low;c[0]=l;for(let t=1;t<o;t++)l=(e[t].high-e[t].low)*s+l*(1-s),c[t]=l;for(let t=n+r;t<o;t++){let n=c[t-r],o={value:n===0?0:(c[t]-n)/n*100};i.set(e[t].time,o),a[t]=o}return{values:i,series:a}}},oc=class extends I{descriptor={id:`rvi`,name:`Relative Vigor Index`,placement:`panel`,defaultConfig:{period:10},inputs:{period:{kind:`int`,min:1}},shortName:`RVGI`,plots:[{key:`value`,title:`RVGI`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=H(t,`period`,10,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a<n+3)return{values:r,series:i};let o=Array(a).fill(0),s=Array(a).fill(0);for(let t=0;t<a;t++)o[t]=e[t].close-e[t].open,s[t]=e[t].high-e[t].low;let c=(e,t)=>(e[t]+2*e[t-1]+2*e[t-2]+e[t-3])/6,l=Array(a).fill(void 0),u=Array(a).fill(void 0);for(let e=3;e<a;e++)l[e]=c(o,e),u[e]=c(s,e);let d=Array(a).fill(void 0);for(let e=3+n-1;e<a;e++){let t=0,r=0;for(let i=e-n+1;i<=e;i++)t+=l[i],r+=u[i];d[e]=r===0?0:t/r}for(let t=0;t<a;t++){if(d[t]===void 0)continue;let n={value:d[t]};t>=3&&d[t-3]!==void 0&&(n.signal=(d[t]+2*d[t-1]+2*d[t-2]+d[t-3])/6),r.set(e[t].time,n),i[t]=n}return{values:r,series:i}}},sc=class extends I{descriptor={id:`stochrsi`,name:`Stochastic RSI`,placement:`panel`,defaultConfig:{rsiPeriod:14,stochPeriod:14,k:3,d:3,source:`close`},shortName:`Stoch RSI`,inputs:{source:{source:!0},rsiPeriod:{kind:`int`,min:1},stochPeriod:{kind:`int`,min:1},k:{kind:`int`,min:1},d:{kind:`int`,min:1}},plots:[{key:`k`,title:`%K`,color:0},{key:`d`,title:`%D`,color:1}],scale:{min:0,max:100},levels:[20,80]};calculate(e,t){let n=H(t,`rsiPeriod`,14,1),r=H(t,`stochPeriod`,14,1),i=H(t,`k`,3,1),a=H(t,`d`,3,1),o=new L,s=Array(e.length).fill(null),c=e.length;if(c<=n+r)return{values:o,series:s};let l=cc(e.map(e=>e.close),n),u=Array(c).fill(void 0);for(let e=0;e<c;e++){if(l[e]===void 0)continue;let t=1/0,n=-1/0,i=!0;for(let a=e-r+1;a<=e;a++){if(a<0||l[a]===void 0){i=!1;break}l[a]<t&&(t=l[a]),l[a]>n&&(n=l[a])}i&&(u[e]=n-t>0?(l[e]-t)/(n-t)*100:0)}let d=lc(u,i),f=lc(d,a);for(let t=0;t<c;t++){if(d[t]===void 0)continue;let n={k:d[t]};f[t]!==void 0&&(n.d=f[t]),o.set(e[t].time,n),s[t]=n}return{values:o,series:s}}};function cc(e,t){let n=e.length,r=Array(n).fill(void 0);if(n<=t)return r;let i=0,a=0;for(let n=1;n<=t;n++){let t=e[n]-e[n-1];t>=0?i+=t:a-=t}i/=t,a/=t,r[t]=a===0?100:100-100/(1+i/a);for(let o=t+1;o<n;o++){let n=e[o]-e[o-1];i=(i*(t-1)+(n>0?n:0))/t,a=(a*(t-1)+(n<0?-n:0))/t,r[o]=a===0?100:100-100/(1+i/a)}return r}function lc(e,t){let n=Array(e.length).fill(void 0);for(let r=t-1;r<e.length;r++){let i=0,a=!0;for(let n=r-t+1;n<=r;n++){if(e[n]===void 0){a=!1;break}i+=e[n]}a&&(n[r]=i/t)}return n}var uc=class extends I{descriptor={id:`ppo`,name:`Percentage Price Oscillator`,placement:`panel`,defaultConfig:{fast:12,slow:26,signal:9,source:`close`},shortName:`PPO`,inputs:{source:{source:!0},fast:{kind:`int`,min:1},slow:{kind:`int`,min:1},signal:{kind:`int`,min:1}},plots:[{key:`hist`,title:`Histogram`,color:2,kind:`histogram`,tone:`sign`,downColor:3},{key:`value`,title:`PPO`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=H(t,`fast`,12,1),r=H(t,`slow`,26,1),i=H(t,`signal`,9,1),a=new L,o=Array(e.length).fill(null),s=e.length;if(s<=r)return{values:a,series:o};let c=e.map(e=>e.close),l=dc(c,n),u=dc(c,r),d=Array(s).fill(void 0);for(let e=0;e<s;e++)l[e]===void 0||u[e]===void 0||u[e]===0||(d[e]=(l[e]-u[e])/u[e]*100);let f=dc(d,i);for(let t=0;t<s;t++){if(d[t]===void 0)continue;let n={value:d[t]};f[t]!==void 0&&(n.signal=f[t],n.hist=d[t]-f[t]),a.set(e[t].time,n),o[t]=n}return{values:a,series:o}}};function dc(e,t){let n=e.length,r=Array(n).fill(void 0),i=2/(t+1),a,o=0,s=0;for(let c=0;c<n;c++){let n=e[c];n!==void 0&&(a===void 0?(o+=n,s++,s===t&&(a=o/t,r[c]=a)):(a=n*i+a*(1-i),r[c]=a))}return r}var fc=class extends I{descriptor={id:`ac`,name:`Accelerator Oscillator`,placement:`panel`,defaultConfig:{},shortName:`AC`,plots:[{key:`value`,title:`AC`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}]};calculate(e){let t=new L,n=Array(e.length).fill(null),r=e.length;if(r<38)return{values:t,series:n};let i=e.map(e=>(e.high+e.low)/2),a=Array(r).fill(void 0);for(let e=33;e<r;e++)a[e]=pc(i,e,5)-pc(i,e,34);let o;for(let i=37;i<r;i++){let r=0;for(let e=i-4;e<=i;e++)r+=a[e];let s=a[i]-r/5,c=o===void 0?s>=0:s>=o;o=s;let l={value:s,up:+!!c};t.set(e[i].time,l),n[i]=l}return{values:t,series:n}}};function pc(e,t,n){let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i];return r/n}var mc=class extends I{descriptor={id:`rmi`,name:`Relative Momentum Index`,placement:`panel`,defaultConfig:{period:20,momentum:5,source:`close`},shortName:`RMI`,inputs:{source:{source:!0},period:{kind:`int`,min:1},momentum:{kind:`int`,min:1}},plots:[{key:`value`,title:`RMI`,color:0}],scale:{min:0,max:100},levels:[30,70]};calculate(e,t){let n=H(t,`period`,20,1),r=H(t,`momentum`,5,1),i=new L,a=Array(e.length).fill(null),o=e.length;if(o<=n+r)return{values:i,series:a};let s=e.map(e=>e.close),c=Array(o).fill(0),l=Array(o).fill(0);for(let e=r;e<o;e++){let t=s[e]-s[e-r];c[e]=t>0?t:0,l[e]=t<0?-t:0}let u=0,d=0,f=r+n;for(let e=r+1;e<=f;e++)u+=c[e],d+=l[e];u/=n,d/=n;let p=t=>{let n={value:d===0?100:100-100/(1+u/d)};i.set(e[t].time,n),a[t]=n};p(f);for(let e=f+1;e<o;e++)u=(u*(n-1)+c[e])/n,d=(d*(n-1)+l[e])/n,p(e);return{values:i,series:a}}},hc=class extends I{descriptor={id:`disparity`,name:`Disparity Index`,placement:`panel`,defaultConfig:{period:14,source:`close`},shortName:`DI`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`DI`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=0;for(let t=0;t<a;t++)if(o+=e[t].close,t>=n&&(o-=e[t-n].close),t>=n-1){let a=o/n,s={value:a===0?0:(e[t].close-a)/a*100};r.set(e[t].time,s),i[t]=s}return{values:r,series:i}}},gc=class extends I{descriptor={id:`qstick`,name:`Qstick`,placement:`panel`,defaultConfig:{period:8},inputs:{period:{kind:`int`,min:1}},shortName:`Qstick`,plots:[{key:`value`,title:`Qstick`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`period`,8,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a<n)return{values:r,series:i};let o=0;for(let t=0;t<a;t++){let a=e[t].close-e[t].open;if(o+=a,t>=n&&(o-=e[t-n].close-e[t-n].open),t>=n-1){let a={value:o/n};r.set(e[t].time,a),i[t]=a}}return{values:r,series:i}}},_c=class extends I{descriptor={id:`pgo`,name:`Pretty Good Oscillator`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`PGO`,plots:[{key:`value`,title:`PGO`,color:0}],levels:[-3,0,3]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null),a=e.length;if(a<=n)return{values:r,series:i};let o=Array(a).fill(0);for(let t=0;t<a;t++){if(t===0){o[t]=e[t].high-e[t].low;continue}let n=e[t-1].close;o[t]=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-n),Math.abs(e[t].low-n))}let s=Array(a).fill(void 0),c=0;for(let e=1;e<=n;e++)c+=o[e];s[n]=c/n;for(let e=n+1;e<a;e++)s[e]=(s[e-1]*(n-1)+o[e])/n;let l=0;for(let t=0;t<a;t++)if(l+=e[t].close,t>=n&&(l-=e[t-n].close),t>=n&&s[t]!==void 0&&s[t]>0){let a=l/n,o={value:(e[t].close-a)/s[t]};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}},vc=class extends I{descriptor={id:`stddev`,name:`Standard Deviation`,placement:`panel`,defaultConfig:{period:20,source:`close`},shortName:`StdDev`,inputs:{source:{source:!0},period:{kind:`int`,min:1}},plots:[{key:`value`,title:`StdDev`,color:0}]};calculate(e,t){let n=H(t,`period`,20,1),r=new L,i=Array(e.length).fill(null);for(let t=n-1;t<e.length;t++){let a=0;for(let r=t-n+1;r<=t;r++)a+=e[r].close;let o=a/n,s=0;for(let r=t-n+1;r<=t;r++){let t=e[r].close-o;s+=t*t}let c={value:Math.sqrt(s/n)};r.set(e[t].time,c),i[t]=c}return{values:r,series:i}}},yc=.3,bc=.7,xc=class extends I{descriptor={id:`volumeProfile`,name:`Volume Profile`,placement:`overlay`,defaultConfig:{rows:24},inputs:{rows:{kind:`int`,min:1}},shortName:`VP`,plots:[]};calculate(e,t){let n=H(t,`rows`,24,1),r=new L,i=Array(e.length).fill(null);if(e.length===0)return{values:r,series:i};let a=1/0,o=-1/0;for(let t of e)t.low<a&&(a=t.low),t.high>o&&(o=t.high);let s=(o-a||1)/n,c=Array(n).fill(0);for(let t of e){let e=(t.high+t.low+t.close)/3,r=Math.min(n-1,Math.floor((e-a)/s));c[r]+=t.volume}for(let e=0;e<n;e++){let t=a+(e+.5)*s;r.set(e,{price:t,volume:c[e],rowIndex:e})}return{values:r,series:i,meta:{minPrice:a,maxPrice:o,rows:n,rowHeight:s,bins:c,maxVolume:Math.max(...c)}}}render(n,r,i,a){let{chartRect:o}=i,s=r.meta;if(!s||s.maxVolume===0)return;let{minPrice:c,rows:l,rowHeight:u,bins:d,maxVolume:f}=s,p=o.width*yc,m=e.E(i),h=a.colors[0]??t.TC_PALETTE.blue,g=a.colors[1]??t.TC_PALETTE.amber;n.save(),n.globalAlpha=yt(a.opacity);for(let e=0;e<l;e++){let t=d[e]/f*p;if(t<=0)continue;let r=m(c+e*u),i=m(c+(e+1)*u);n.fillStyle=d[e]>f*bc?g:h,n.fillRect(o.x,Math.min(r,i),t,Math.max(Math.abs(r-i)-1,1))}n.restore()}},Sc=class extends I{descriptor={id:`ad`,name:`Accumulation/Distribution`,placement:`panel`,defaultConfig:{},shortName:`A/D`,plots:[{key:`value`,title:`A/D`,color:0}]};calculate(e,t){let n=new L,r=Array(e.length).fill(null);if(e.length===0)return{values:n,series:r};let i=0;for(let t=0;t<e.length;t++){let a=e[t].high-e[t].low,o=a===0?0:(e[t].close-e[t].low-(e[t].high-e[t].close))/a;i+=o*e[t].volume;let s={value:i};n.set(e[t].time,s),r[t]=s}return{values:n,series:r}}},Cc=class extends I{descriptor={id:`vroc`,name:`Volume Rate of Change`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:1}},shortName:`VROC`,plots:[{key:`value`,title:`VROC`,color:0}],levels:[0]};calculate(e,t){let n=H(t,`period`,14,1),r=new L,i=Array(e.length).fill(null);for(let t=n;t<e.length;t++){let a=e[t-n].volume,o={value:a===0?0:(e[t].volume-a)/a*100};r.set(e[t].time,o),i[t]=o}return{values:r,series:i}}},wc=class extends I{descriptor={id:`dema`,name:`Double Exponential Moving Average`,placement:`overlay`,defaultConfig:{period:20,source:`close`},shortName:`DEMA`,inputs:{period:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`value`,title:`DEMA`,color:0}]};emas=new WeakMap;workerState(e){return this.emas.get(e)}adoptWorkerState(e,t){t&&this.emas.set(e,t)}calculate(e,t){let n=H(t,`period`,20,1),r=z(Fa(e),n),i=z(r,n),a=R(e,Wa(r.map((e,t)=>e!==void 0&&i[t]!==void 0?2*e-i[t]:void 0)));return this.emas.set(a,{e1:r,e2:i}),a}update(e,t,n,r){let i=this.emas.get(n);if(!i||!this.canResume(e,n,r))return null;let a=i.e1[r-1],o=i.e2[r-1];if(a===void 0||o===void 0)return null;let s=2/(H(t,`period`,20,1)+1);for(let t=r;t<e.length;t++)a+=s*(e[t].close-a),o+=s*(a-o),i.e1[t]=a,i.e2[t]=o,this.writePoint(n,e,t,{value:2*a-o});return n}},Tc=class extends I{descriptor={id:`smma`,name:`Smoothed Moving Average`,placement:`overlay`,defaultConfig:{period:14,source:`close`},shortName:`SMMA`,inputs:{period:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`value`,title:`SMMA`,color:0}]};calculate(e,t){return R(e,Wa(za(Fa(e),H(t,`period`,14,1))))}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=n.series[r-1]?.value;if(i===void 0)return null;let a=H(t,`period`,14,1);for(let t=r;t<e.length;t++)i+=(e[t].close-i)/a,this.writePoint(n,e,t,{value:i});return n}},Ec=class extends B{descriptor={id:`alma`,name:`Arnaud Legoux Moving Average`,placement:`overlay`,defaultConfig:{period:9,offset:.85,sigma:6,source:`close`},shortName:`ALMA`,inputs:{period:{kind:`int`,min:1,max:5e3},offset:{kind:`number`,min:0,max:1,step:.05},sigma:{kind:`number`,min:.5,step:.5},source:{source:!0}},plots:[{key:`value`,title:`ALMA`,color:0}]};read(e){let t=Math.min(5e3,H(e,`period`,9,1)),n=Math.min(1,Math.max(0,V(e,`offset`,.85))),r=Math.max(.5,V(e,`sigma`,6)),i=n*(t-1),a=t/r,o=Array.from({length:t},(e,t)=>Math.exp(-((t-i)**2)/(2*a*a)));return{period:t,weights:o,norm:o.reduce((e,t)=>e+t,0)}}pointAt(e,t,{period:n,weights:r,norm:i}){if(t<n-1)return null;let a=0;for(let i=0;i<n;i++)a+=r[i]*e[t-n+1+i].close;return{value:a/i}}},Dc=class extends I{descriptor={id:`kama`,name:`Kaufman Adaptive Moving Average`,placement:`overlay`,defaultConfig:{period:10,fast:2,slow:30,source:`close`},shortName:`KAMA`,inputs:{period:{kind:`int`,min:1},fast:{kind:`int`,min:1},slow:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`value`,title:`KAMA`,color:0}]};calculate(e,t){let n=R(e,Array(e.length).fill(null)),r=H(t,`period`,10,1);return e.length<=r||this.extend(e,t,n,r,e[r-1].close),n}update(e,t,n,r){if(r<=H(t,`period`,10,1)||!this.canResume(e,n,r))return null;let i=n.series[r-1]?.value;return i===void 0?null:(this.extend(e,t,n,r,i),n)}extend(e,t,n,r,i){let a=H(t,`period`,10,1),o=2/(H(t,`fast`,2,1)+1),s=2/(H(t,`slow`,30,1)+1);for(let t=r;t<e.length;t++){let r=0;for(let n=t-a+1;n<=t;n++)r+=Math.abs(e[n].close-e[n-1].close);let c=Math.abs(e[t].close-e[t-a].close),l=((r>0?c/r:0)*(o-s)+s)**2;i+=l*(e[t].close-i),this.writePoint(n,e,t,{value:i})}}},Oc=class extends B{descriptor={id:`lsma`,name:`Least Squares Moving Average`,placement:`overlay`,defaultConfig:{period:25,offset:0,source:`close`},shortName:`LSMA`,inputs:{period:{kind:`int`,min:2,max:5e3},offset:{kind:`int`,step:1},source:{source:!0}},plots:[{key:`value`,title:`LSMA`,color:0}]};read(e){let t=Math.min(5e3,H(e,`period`,25,2)),n=Math.round(H(e,`offset`,0,-1e3)),r=t*(t-1)/2;return{period:t,offset:n,sx:r,denom:t*((t-1)*t*(2*t-1)/6)-r*r}}pointAt(e,t,{period:n,offset:r,sx:i,denom:a}){if(t<n-1)return null;let o=0,s=0;for(let r=0;r<n;r++){let i=e[t-n+1+r].close;o+=i,s+=r*i}let c=(n*s-i*o)/a;return{value:(o-c*i)/n+c*(n-1-r)}}},kc=class extends I{descriptor={id:`mcginley`,name:`McGinley Dynamic`,placement:`overlay`,defaultConfig:{period:14,source:`close`},shortName:`McGinley`,inputs:{period:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`value`,title:`McGinley`,color:0}]};calculate(e,t){let n=H(t,`period`,14,1),r=z(Fa(e),n),i=Array(e.length).fill(void 0),a;for(let t=0;t<e.length;t++)a=a===void 0?r[t]:Ac(a,e[t].close,n),i[t]=a;return R(e,Wa(i))}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let i=n.series[r-1]?.value;if(i===void 0)return null;let a=H(t,`period`,14,1);for(let t=r;t<e.length;t++)i=Ac(i,e[t].close,a),this.writePoint(n,e,t,{value:i});return n}};function Ac(e,t,n){return e>0&&t>0?e+(t-e)/(n*(t/e)**4):t}function jc(e){return e.params.type===`ema`?[`ema`,`ema`]:e.params.type===`sma-ema`?[`sma`,`ema`]:[`sma`,`sma`]}var Mc=class extends I{descriptor={id:`macross`,name:`MA Cross`,placement:`overlay`,defaultConfig:{fast:9,slow:21,type:`sma`,source:`close`},shortName:`MA Cross`,inputs:{fast:{kind:`int`,min:1},slow:{kind:`int`,min:1},type:{options:[`sma`,`ema`,`sma-ema`]},source:{source:!0}},plots:[{key:`fast`,title:`Fast`,color:0},{key:`slow`,title:`Slow`,color:1}]};calculate(e,t){let[n,r]=jc(t),i=Fa(e),a=(t,n)=>t===`ema`?z(i,n):e.map((t,r)=>Ja(e,r,n)),o=a(n,H(t,`fast`,9,1)),s=a(r,H(t,`slow`,21,1));return R(e,o.map((e,t)=>Nc(e,s[t])))}update(e,t,n,r){if(!this.canResume(e,n,r))return null;let[i,a]=jc(t),o=H(t,`fast`,9,1),s=H(t,`slow`,21,1),c=n.series[r-1]?.fast,l=n.series[r-1]?.slow;if(i===`ema`&&c===void 0||a===`ema`&&l===void 0)return null;for(let t=r;t<e.length;t++){let r=e[t].close;c=i===`ema`?c+2/(o+1)*(r-c):Ja(e,t,o),l=a===`ema`?l+2/(s+1)*(r-l):Ja(e,t,s),this.writePoint(n,e,t,Nc(c,l))}return n}};function Nc(e,t){return e===void 0&&t===void 0?null:{...e===void 0?{}:{fast:e},...t===void 0?{}:{slow:t}}}var Pc=class extends B{descriptor={id:`fractals`,name:`Williams Fractals`,placement:`overlay`,defaultConfig:{period:2},shortName:`Fractals`,inputs:{period:{kind:`int`,min:1,max:10}},plots:[{key:`up`,title:`Up`,color:0,kind:`dots`},{key:`down`,title:`Down`,color:1,kind:`dots`}]};read(e){return H(e,`period`,2,1)}lookback(e){return e}pointAt(e,t,n){if(t<n||t>e.length-n-1)return null;let r=!0,i=!0;for(let a=t-n;a<=t+n&&(r||i);a++)a!==t&&(e[a].high>=e[t].high&&(r=!1),e[a].low<=e[t].low&&(i=!1));return!r&&!i?null:{...r?{up:e[t].high}:{},...i?{down:e[t].low}:{}}}},Fc=class extends I{descriptor={id:`cks`,name:`Chande Kroll Stop`,placement:`overlay`,defaultConfig:{p:10,x:1,q:9},shortName:`CKS`,inputs:{p:{kind:`int`,label:`ATR length`,min:1},x:{kind:`number`,label:`ATR multiplier`,min:0,step:.1},q:{kind:`int`,label:`Stop length`,min:1}},plots:[{key:`long`,title:`Stop Long`,color:0},{key:`short`,title:`Stop Short`,color:1}]};states=new WeakMap;workerState(e){return this.states.get(e)}adoptWorkerState(e,t){t&&this.states.set(e,t)}calculate(e,t){let n=H(t,`p`,10,1),r=V(t,`x`,1),i=H(t,`q`,9,1),a={atr:za(Va(e),n),firstHigh:[],firstLow:[]};for(let t=0;t<e.length;t++)Ic(e,a,t,n,r);let o=R(e,e.map((e,t)=>Lc(a,t,i)));return this.states.set(o,a),o}update(e,t,n,r){let i=this.states.get(n);if(!i||!this.canResume(e,n,r))return null;let a=i.atr[r-1];if(a===void 0)return null;let o=H(t,`p`,10,1),s=V(t,`x`,1),c=H(t,`q`,9,1);for(let t=r;t<e.length;t++){let r=e[t-1].close,l=Math.max(e[t].high-e[t].low,Math.abs(e[t].high-r),Math.abs(e[t].low-r));a+=(l-a)/o,i.atr[t]=a,Ic(e,i,t,o,s),this.writePoint(n,e,t,Lc(i,t,c))}return n}};function Ic(e,t,n,r,i){let a=t.atr[n],o=Ka(e,n,r),s=qa(e,n,r);t.firstHigh[n]=o!==void 0&&a!==void 0?o-i*a:void 0,t.firstLow[n]=s!==void 0&&a!==void 0?s+i*a:void 0}function Lc(e,t,n){let r=Ha(e.firstHigh,t,n),i=Ua(e.firstLow,t,n);return r!==void 0&&i!==void 0?{long:i,short:r}:null}var Rc=class extends B{descriptor={id:`bbpb`,name:`Bollinger Bands %B`,placement:`panel`,defaultConfig:{period:20,stdDev:2,source:`close`},shortName:`%B`,inputs:{period:{kind:`int`,min:2},stdDev:{kind:`number`,min:.1,step:.1},source:{source:!0}},plots:[{key:`value`,title:`%B`,color:0}],levels:[0,.5,1]};read(e){return{period:H(e,`period`,20,2),k:V(e,`stdDev`,2)}}pointAt(e,t,{period:n,k:r}){let i=Ga(e,t,n);return!i||i.sd===0?null:{value:(e[t].close-(i.mean-r*i.sd))/(2*r*i.sd)}}},zc=class extends B{descriptor={id:`bbw`,name:`Bollinger BandWidth`,placement:`panel`,defaultConfig:{period:20,stdDev:2,source:`close`},shortName:`BBW`,inputs:{period:{kind:`int`,min:2},stdDev:{kind:`number`,min:.1,step:.1},source:{source:!0}},plots:[{key:`value`,title:`BBW`,color:0}]};read(e){return{period:H(e,`period`,20,2),k:V(e,`stdDev`,2)}}pointAt(e,t,{period:n,k:r}){let i=Ga(e,t,n);return!i||i.mean===0?null:{value:2*r*i.sd/i.mean}}},Bc=class extends B{descriptor={id:`mom`,name:`Momentum`,placement:`panel`,defaultConfig:{period:10,source:`close`},shortName:`MOM`,inputs:{period:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`value`,title:`MOM`,color:0}],levels:[0]};read(e){return H(e,`period`,10,1)}pointAt(e,t,n){return t>=n?{value:e[t].close-e[t-n].close}:null}},Vc=class extends B{descriptor={id:`hv`,name:`Historical Volatility`,placement:`panel`,defaultConfig:{period:10,annual:365,source:`close`},shortName:`HV`,inputs:{period:{kind:`int`,min:2},annual:{kind:`number`,label:`Bars per year`,min:1},source:{source:!0}},plots:[{key:`value`,title:`HV`,color:0}],scale:{min:0}};read(e){return{period:H(e,`period`,10,2),annual:Math.max(1,V(e,`annual`,365))}}pointAt(e,t,{period:n,annual:r}){if(t<n)return null;let i=0,a=0;for(let r=t-n+1;r<=t;r++){let t=e[r-1].close,n=e[r].close;if(!(t>0&&n>0))return null;let o=Math.log(n/t);i+=o,a+=o*o}let o=i/n;return{value:100*Math.sqrt(Math.max(0,a/n-o*o))*Math.sqrt(r)}}},Hc=class extends I{descriptor={id:`vo`,name:`Volume Oscillator`,placement:`panel`,defaultConfig:{short:5,long:10},shortName:`Vol Osc`,inputs:{short:{kind:`int`,min:1},long:{kind:`int`,min:1}},plots:[{key:`value`,title:`Vol Osc`,color:0}],levels:[0]};emas=new WeakMap;workerState(e){return this.emas.get(e)}adoptWorkerState(e,t){t&&this.emas.set(e,t)}calculate(e,t){let n=e.map(e=>e.volume),r=z(n,H(t,`short`,5,1)),i=z(n,H(t,`long`,10,1)),a=R(e,Wa(r.map((e,t)=>Uc(e,i[t]))));return this.emas.set(a,{fast:r,slow:i}),a}update(e,t,n,r){let i=this.emas.get(n);if(!i||!this.canResume(e,n,r))return null;let a=i.fast[r-1],o=i.slow[r-1];if(a===void 0||o===void 0)return null;let s=2/(H(t,`short`,5,1)+1),c=2/(H(t,`long`,10,1)+1);for(let t=r;t<e.length;t++){a+=s*(e[t].volume-a),o+=c*(e[t].volume-o),i.fast[t]=a,i.slow[t]=o;let r=Uc(a,o);this.writePoint(n,e,t,r===void 0?null:{value:r})}return n}};function Uc(e,t){return e===void 0||t===void 0||t===0?void 0:100*(e-t)/t}var Wc=class extends I{descriptor={id:`ulcer`,name:`Ulcer Index`,placement:`panel`,defaultConfig:{period:14,source:`close`},shortName:`Ulcer`,inputs:{period:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`value`,title:`Ulcer`,color:0}],scale:{min:0}};drawdowns=new WeakMap;workerState(e){return this.drawdowns.get(e)}adoptWorkerState(e,t){t&&this.drawdowns.set(e,t)}calculate(e,t){let n=H(t,`period`,14,1),r=e.map((t,r)=>Gc(e,r,n)),i=R(e,e.map((e,t)=>Kc(r,t,n)));return this.drawdowns.set(i,r),i}update(e,t,n,r){let i=this.drawdowns.get(n);if(!i||!this.canResume(e,n,r))return null;let a=H(t,`period`,14,1);for(let t=r;t<e.length;t++)i[t]=Gc(e,t,a);i.length=e.length;for(let t=r;t<e.length;t++)this.writePoint(n,e,t,Kc(i,t,a));return n}};function Gc(e,t,n){if(t<n-1)return;let r=-1/0;for(let i=t-n+1;i<=t;i++)e[i].close>r&&(r=e[i].close);return r===0?void 0:100*(e[t].close-r)/r}function Kc(e,t,n){if(t<n-1)return null;let r=0;for(let i=t-n+1;i<=t;i++){let t=e[i];if(t===void 0)return null;r+=t*t}return{value:Math.sqrt(r/n)}}var qc=class extends I{descriptor={id:`smi`,name:`Stochastic Momentum Index`,placement:`panel`,defaultConfig:{period:10,smooth:3,signal:3},shortName:`SMI`,inputs:{period:{kind:`int`,min:1},smooth:{kind:`int`,min:1},signal:{kind:`int`,min:1}},plots:[{key:`smi`,title:`SMI`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[40,-40]};calculate(e,t){let n=H(t,`period`,10,1),r=H(t,`smooth`,3,1),i=H(t,`signal`,3,1),a=Array(e.length).fill(void 0),o=Array(e.length).fill(void 0);for(let t=n-1;t<e.length;t++){let r=Ka(e,t,n),i=qa(e,t,n);r===void 0||i===void 0||(a[t]=e[t].close-(r+i)/2,o[t]=r-i)}let s=z(z(a,r),r),c=z(z(o,r),r),l=s.map((e,t)=>{let n=c[t]===void 0?void 0:c[t]/2;if(!(e===void 0||n===void 0))return n===0?0:Math.max(-100,Math.min(100,100*e/n))}),u=z(l,i);return R(e,l.map((e,t)=>{if(e===void 0)return null;let n={smi:e};return u[t]!==void 0&&(n.signal=u[t]),n}))}},Jc=class extends I{descriptor={id:`rvix`,name:`Relative Volatility Index`,placement:`panel`,defaultConfig:{period:10,smooth:14},shortName:`RVI (vol)`,inputs:{period:{kind:`int`,min:2},smooth:{kind:`int`,min:1}},plots:[{key:`value`,title:`RVI`,color:0}],levels:[80,50,20],scale:{min:0,max:100}};calculate(e,t){let n=H(t,`period`,10,2),r=H(t,`smooth`,14,1),i=Ba(Fa(e),n),a=i.map((t,n)=>t===void 0||n===0?void 0:e[n].close>e[n-1].close?t:0),o=i.map((t,n)=>t===void 0||n===0?void 0:e[n].close<e[n-1].close?t:0),s=z(a,r),c=z(o,r);return R(e,Wa(s.map((e,t)=>{let n=c[t];if(!(e===void 0||n===void 0))return e+n===0?50:100*e/(e+n)})))}},Yc=class extends B{descriptor={id:`trendstrength`,name:`Trend Strength Index`,placement:`panel`,defaultConfig:{period:14},shortName:`TSI (trend)`,inputs:{period:{kind:`int`,min:2}},plots:[{key:`value`,title:`Trend`,color:0}],levels:[0],scale:{min:-1,max:1}};read(e){return H(e,`period`,14,2)}pointAt(e,t,n){let r=Ya(e,t,n);return r?{value:r.r}:null}},Xc=class extends B{descriptor={id:`lrslope`,name:`Linear Regression Slope`,placement:`panel`,defaultConfig:{period:14},shortName:`LR Slope`,inputs:{period:{kind:`int`,min:2}},plots:[{key:`value`,title:`Slope`,color:0}],levels:[0]};read(e){return H(e,`period`,14,2)}pointAt(e,t,n){let r=Ya(e,t,n);return r?{value:r.slope}:null}},Zc=class extends B{descriptor={id:`stderror`,name:`Standard Error`,placement:`panel`,defaultConfig:{period:14},shortName:`StdErr`,inputs:{period:{kind:`int`,min:3}},plots:[{key:`value`,title:`StdErr`,color:0}],scale:{min:0}};read(e){return H(e,`period`,14,3)}pointAt(e,t,n){let r=Ya(e,t,n);return r?{value:r.stdErr}:null}},Qc=class extends B{descriptor={id:`adr`,name:`Average Day Range`,placement:`panel`,defaultConfig:{period:14},shortName:`ADR`,inputs:{period:{kind:`int`,min:1}},plots:[{key:`value`,title:`ADR`,color:0}],scale:{min:0}};read(e){return H(e,`period`,14,1)}pointAt(e,t,n){if(t<n-1)return null;let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i].high-e[i].low;return{value:r/n}}},$c=class extends B{descriptor={id:`netvolume`,name:`Net Volume`,placement:`panel`,defaultConfig:{},shortName:`Net Vol`,plots:[{key:`value`,title:`Net`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}],levels:[0]};read(e){return null}pointAt(e,t){if(t===0)return null;let n=e[t].close-e[t-1].close,r=e[t].volume??0;return{value:n>0?r:n<0?-r:0,up:+(n>=0)}}lookback(){return 1}},el=class extends I{descriptor={id:`seb`,name:`Standard Error Bands`,placement:`overlay`,defaultConfig:{period:21,mult:2,smooth:3},shortName:`SEB`,inputs:{period:{kind:`int`,min:3},mult:{kind:`number`,min:0,step:.1},smooth:{kind:`int`,min:1}},plots:[{key:`upper`,title:`Upper`,color:1},{key:`middle`,title:`Middle`,color:0},{key:`lower`,title:`Lower`,color:1}]};calculate(e,t){let n=H(t,`period`,21,3),r=V(t,`mult`,2),i=H(t,`smooth`,3,1),a=Array(e.length).fill(void 0),o=Array(e.length).fill(void 0),s=Array(e.length).fill(void 0);for(let t=0;t<e.length;t++){let i=Ya(e,t,n);i&&(a[t]=i.end,o[t]=i.end+r*i.stdErr,s[t]=i.end-r*i.stdErr)}let c=Ia(a,i),l=Ia(o,i),u=Ia(s,i);return R(e,c.map((e,t)=>e===void 0||l[t]===void 0||u[t]===void 0?null:{middle:e,upper:l[t],lower:u[t]}))}},tl=[3,5,8,10,12,15],nl=[30,35,40,45,50,60],rl=class extends I{descriptor={id:`gmma`,name:`Guppy Multiple Moving Average`,placement:`overlay`,defaultConfig:{},shortName:`GMMA`,plots:[...tl.map(e=>({key:`s${e}`,title:`EMA ${e}`,color:0})),...nl.map(e=>({key:`l${e}`,title:`EMA ${e}`,color:1}))]};calculate(e,t){let n=Fa(e),r=[...tl.map(e=>[`s${e}`,z(n,e)]),...nl.map(e=>[`l${e}`,z(n,e)])];return R(e,e.map((e,t)=>{let n={},i=!1;for(let[e,a]of r)a[t]!==void 0&&(n[e]=a[t],i=!0);return i?n:null}))}},il=class extends I{descriptor={id:`maribbon`,name:`Moving Average Ribbon`,placement:`overlay`,defaultConfig:{ma1:20,ma2:50,ma3:100,ma4:200,exponential:0},shortName:`MA Ribbon`,inputs:{ma1:{kind:`int`,min:1},ma2:{kind:`int`,min:1},ma3:{kind:`int`,min:1},ma4:{kind:`int`,min:1},exponential:{kind:`int`,min:0,max:1}},plots:[{key:`ma1`,title:`MA 1`,color:0},{key:`ma2`,title:`MA 2`,color:1},{key:`ma3`,title:`MA 3`,color:2},{key:`ma4`,title:`MA 4`,color:3}]};calculate(e,t){let n=V(t,`exponential`,0)>=1?z:Ia,r=Fa(e),i=[`ma1`,`ma2`,`ma3`,`ma4`],a=[20,50,100,200],o=i.map((e,i)=>[e,n(r,H(t,e,a[i],1))]);return R(e,e.map((e,t)=>{let n={},r=!1;for(let[e,i]of o)i[t]!==void 0&&(n[e]=i[t],r=!0);return r?n:null}))}},al=class extends B{read(e){return null}pointAt(e,t){return{value:this.price(e[t])}}},ol=class extends al{descriptor={id:`avgprice`,name:`Average Price`,placement:`overlay`,defaultConfig:{},shortName:`OHLC4`,plots:[{key:`value`,title:`Average`,color:0}]};price(e){return(e.open+e.high+e.low+e.close)/4}},sl=class extends al{descriptor={id:`medprice`,name:`Median Price`,placement:`overlay`,defaultConfig:{},shortName:`HL2`,plots:[{key:`value`,title:`Median`,color:0}]};price(e){return(e.high+e.low)/2}},cl=class extends al{descriptor={id:`typprice`,name:`Typical Price`,placement:`overlay`,defaultConfig:{},shortName:`HLC3`,plots:[{key:`value`,title:`Typical`,color:0}]};price(e){return(e.high+e.low+e.close)/3}},ll=class extends al{descriptor={id:`wclose`,name:`Weighted Close`,placement:`overlay`,defaultConfig:{},shortName:`HLCC4`,plots:[{key:`value`,title:`Weighted`,color:0}]};price(e){return(e.high+e.low+2*e.close)/4}},ul=class extends B{descriptor={id:`psy`,name:`Psychological Line`,placement:`panel`,defaultConfig:{period:10},inputs:{period:{kind:`int`,min:1}},shortName:`PSY`,plots:[{key:`value`,title:`PSY`,color:0}],scale:{min:0,max:100},levels:[25,75]};read(e){return H(e,`period`,10,1)}pointAt(e,t,n){if(t<n)return null;let r=0;for(let i=t-n+1;i<=t;i++)e[i].close>e[i-1].close&&r++;return{value:r/n*100}}},dl=class extends B{descriptor={id:`newpsy`,name:`New Psychological Line`,placement:`panel`,defaultConfig:{period:10},inputs:{period:{kind:`int`,min:1}},shortName:`New PSY`,plots:[{key:`value`,title:`New PSY`,color:0}],scale:{min:-100,max:100},levels:[-50,0,50]};read(e){return H(e,`period`,10,1)}pointAt(e,t,n){if(t<n)return null;let r=0,i=0,a=0,o=0;for(let s=t-n+1;s<=t;s++){let t=e[s].close-e[s-1].close;t>0?(r++,a+=t):t<0&&(i++,o-=t)}let s=a+o;return{value:s===0?0:(r*a-i*o)/(s*n)*100}}},fl=class extends B{descriptor={id:`vr`,name:`Volume Ratio`,placement:`panel`,defaultConfig:{period:20},inputs:{period:{kind:`int`,min:1}},shortName:`VR`,plots:[{key:`value`,title:`VR`,color:0}],levels:[70,150,450]};read(e){return H(e,`period`,20,1)}pointAt(e,t,n){if(t<n)return null;let r=0,i=0,a=0;for(let o=t-n+1;o<=t;o++){let t=e[o].close-e[o-1].close;t>0?r+=e[o].volume:t<0?i+=e[o].volume:a+=e[o].volume}let o=i+a/2;return o>0?{value:(r+a/2)/o*100}:null}},pl=class extends B{descriptor={id:`abratio`,name:`AB Ratio`,placement:`panel`,defaultConfig:{period:26},inputs:{period:{kind:`int`,min:1}},shortName:`AB Ratio`,plots:[{key:`a`,title:`A`,color:0},{key:`b`,title:`B`,color:1}],levels:[100]};read(e){return H(e,`period`,26,1)}pointAt(e,t,n){if(t<n)return null;let r=0,i=0,a=0,o=0;for(let s=t-n+1;s<=t;s++){let{open:t,high:n,low:c}=e[s],l=e[s-1].close;r+=n-t,i+=t-c,a+=Math.max(0,n-l),o+=Math.max(0,l-c)}let s={};return i>0&&(s.a=r/i*100),o>0&&(s.b=a/o*100),s.a!==void 0||s.b!==void 0?s:null}},ml=class extends I{descriptor={id:`sonar`,name:`Sonar`,placement:`panel`,defaultConfig:{period:20,lookback:9,signal:9},inputs:{period:{kind:`int`,min:1},lookback:{kind:`int`,min:1},signal:{kind:`int`,min:1}},shortName:`Sonar`,plots:[{key:`sonar`,title:`Sonar`,color:0},{key:`signal`,title:`Signal`,color:1}],levels:[0]};calculate(e,t){let n=H(t,`period`,20,1),r=H(t,`lookback`,9,1),i=H(t,`signal`,9,1),a=z(Fa(e),n),o=a.map((e,t)=>e!==void 0&&t>=r&&a[t-r]!==void 0?e-a[t-r]:void 0),s=z(o,i);return R(e,o.map((e,t)=>e===void 0?null:s[t]===void 0?{sonar:e}:{sonar:e,signal:s[t]}))}},hl=class extends B{descriptor={id:`sigma`,name:`Sigma`,placement:`panel`,defaultConfig:{period:20},inputs:{period:{kind:`int`,min:2}},shortName:`Sigma`,plots:[{key:`value`,title:`Sigma`,color:0}],levels:[-2,0,2]};read(e){return H(e,`period`,20,2)}pointAt(e,t,n){let r=Ga(e,t,n);return r?{value:r.sd<=Math.abs(r.mean)*1e-9?0:(e[t].close-r.mean)/r.sd}:null}},gl=class extends B{descriptor={id:`vhf`,name:`Vertical Horizontal Filter`,placement:`panel`,defaultConfig:{period:28},inputs:{period:{kind:`int`,min:1}},shortName:`VHF`,plots:[{key:`value`,title:`VHF`,color:0}]};read(e){return H(e,`period`,28,1)}pointAt(e,t,n){if(t<n)return null;let r=e[t-n].close,i=r,a=0;for(let o=t-n+1;o<=t;o++){let t=e[o].close;t>r&&(r=t),t<i&&(i=t),a+=Math.abs(t-e[o-1].close)}return a>0?{value:(r-i)/a}:null}},_l=class extends B{descriptor={id:`rsquared`,name:`R-Squared`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:2}},shortName:`R²`,plots:[{key:`value`,title:`R²`,color:0}],scale:{min:0,max:1}};read(e){return H(e,`period`,14,2)}pointAt(e,t,n){let r=Ya(e,t,n);return r?{value:r.r*r.r}:null}};function vl(e,t){let n=e[t];if(t===0)return n.high-n.low;let r=e[t-1].close;return Math.max(n.high-n.low,Math.abs(n.high-r),Math.abs(n.low-r))}var yl=class extends B{descriptor={id:`rwi`,name:`Random Walk Index`,placement:`panel`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:2}},shortName:`RWI`,plots:[{key:`high`,title:`RWI High`,color:0},{key:`low`,title:`RWI Low`,color:1}],levels:[1]};read(e){return H(e,`period`,14,2)}pointAt(e,t,n){if(t<n)return null;let r=0,i=0,a=vl(e,t);for(let o=1;o<=n;o++){if(o>1){let n=a/o*Math.sqrt(o);n>0&&(r=Math.max(r,(e[t].high-e[t-o].low)/n),i=Math.max(i,(e[t-o].high-e[t].low)/n))}a+=vl(e,t-o)}return{high:r,low:i}}},bl=1e3,xl=class extends I{calculate(e,t){let n=Array(e.length).fill(void 0),r=bl;for(let t=0;t<e.length;t++){if(t>0){let n=e[t-1].close;n!==0&&this.counts(e[t].volume,e[t-1].volume)&&(r*=e[t].close/n)}n[t]=r}let i=z(n,H(t,`signal`,255,1));return R(e,n.map((e,t)=>i[t]===void 0?{value:e}:{value:e,signal:i[t]}))}},Sl=class extends xl{descriptor={id:`nvi`,name:`Negative Volume Index`,placement:`panel`,defaultConfig:{signal:255},inputs:{signal:{kind:`int`,min:1}},shortName:`NVI`,plots:[{key:`value`,title:`NVI`,color:0},{key:`signal`,title:`Signal`,color:1}]};counts(e,t){return e<t}},Cl=class extends xl{descriptor={id:`pvi`,name:`Positive Volume Index`,placement:`panel`,defaultConfig:{signal:255},inputs:{signal:{kind:`int`,min:1}},shortName:`PVI`,plots:[{key:`value`,title:`PVI`,color:0},{key:`signal`,title:`Signal`,color:1}]};counts(e,t){return e>t}},wl=class extends B{descriptor={id:`tr`,name:`True Range`,placement:`panel`,defaultConfig:{},shortName:`TR`,plots:[{key:`value`,title:`TR`,color:0}]};read(e){return null}pointAt(e,t){let n=e[t];if(t===0)return{value:n.high-n.low};let r=e[t-1].close;return{value:Math.max(n.high-n.low,Math.abs(n.high-r),Math.abs(n.low-r))}}},Tl=class extends B{descriptor={id:`iii`,name:`Intraday Intensity`,placement:`panel`,defaultConfig:{period:21},inputs:{period:{kind:`int`,min:1}},shortName:`III`,plots:[{key:`value`,title:`III %`,color:0,kind:`histogram`,tone:`sign`,downColor:1}],scale:{zero:!0},levels:[0]};read(e){return H(e,`period`,21,1)}pointAt(e,t,n){if(t<n-1)return null;let r=0,i=0;for(let a=t-n+1;a<=t;a++){let t=e[a];i+=t.volume,t.high>t.low&&(r+=t.volume*(2*t.close-t.high-t.low)/(t.high-t.low))}return i>0?{value:Math.max(-100,Math.min(100,r/i*100))}:{value:0}}},El=class extends B{descriptor={id:`volpct`,name:`Volume vs Average`,placement:`panel`,defaultConfig:{period:20},inputs:{period:{kind:`int`,min:1}},shortName:`Vol %`,plots:[{key:`value`,title:`Vol %`,color:0,kind:`histogram`,tone:`sign`,downColor:1}],scale:{zero:!0},levels:[0]};read(e){return H(e,`period`,20,1)}pointAt(e,t,n){if(t<n-1)return null;let r=0;for(let i=t-n+1;i<=t;i++)r+=e[i].volume;let i=r/n,a=(e[t].volume-i)/i*100;return i>0&&Number.isFinite(a)?{value:a}:null}},Dl=class extends B{descriptor={id:`volchange`,name:`Volume Change`,placement:`panel`,defaultConfig:{},shortName:`Vol Δ`,plots:[{key:`value`,title:`Volume`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}],scale:{zero:!0}};read(e){return null}pointAt(e,t){let{volume:n}=e[t];return Number.isFinite(n)?{value:n,up:+(t===0||n>=e[t-1].volume)}:null}},Ol=class extends B{descriptor={id:`tradevalue`,name:`Trade Value`,placement:`panel`,defaultConfig:{},shortName:`Value`,plots:[{key:`value`,title:`Value`,color:0,kind:`histogram`,tone:{field:`up`},downColor:1}],scale:{zero:!0}};read(e){return null}pointAt(e,t){let n=e[t],r=n.close*n.volume;return Number.isFinite(r)?{value:r,up:+(n.close>=n.open)}:null}},kl=class extends I{descriptor={id:`binarywave`,name:`Binary Wave`,placement:`panel`,defaultConfig:{ma:20,fast:12,slow:26,signal:9,roc:12,stoch:14},inputs:{ma:{kind:`int`,min:1},fast:{kind:`int`,min:1},slow:{kind:`int`,min:1},signal:{kind:`int`,min:1},roc:{kind:`int`,min:1},stoch:{kind:`int`,min:1}},shortName:`Binary Wave`,plots:[{key:`value`,title:`Wave`,color:0,kind:`step`}],scale:{min:-4,max:4},levels:[0]};calculate(e,t){let n=Fa(e),r=Ia(n,H(t,`ma`,20,1)),i=z(n,H(t,`fast`,12,1)),a=z(n,H(t,`slow`,26,1)),o=i.map((e,t)=>e!==void 0&&a[t]!==void 0?e-a[t]:void 0),s=z(o,H(t,`signal`,9,1)),c=H(t,`roc`,12,1),l=H(t,`stoch`,14,1),u=e=>e?1:-1;return R(e,Wa(e.map((t,i)=>{let a=Ka(e,i,l),d=qa(e,i,l);if(r[i]===void 0||o[i]===void 0||s[i]===void 0||i<c||a===void 0||d===void 0)return;let f=a>d?(t.close-d)/(a-d)*100:50;return u(t.close>r[i])+u(o[i]>s[i])+u(t.close>n[i-c])+u(f>50)})))}},Al=class extends I{descriptor={id:`sroc`,name:`Smoothed Rate of Change`,placement:`panel`,defaultConfig:{ema:13,roc:21},inputs:{ema:{kind:`int`,min:1},roc:{kind:`int`,min:1}},shortName:`S-ROC`,plots:[{key:`value`,title:`S-ROC`,color:0}],levels:[0]};calculate(e,t){let n=z(Fa(e),H(t,`ema`,13,1)),r=H(t,`roc`,21,1);return R(e,Wa(n.map((e,t)=>{let i=t>=r?n[t-r]:void 0;return e!==void 0&&i!==void 0&&i!==0?(e-i)/Math.abs(i)*100:void 0})))}},jl=class extends B{descriptor={id:`tsf`,name:`Time Series Forecast`,placement:`overlay`,defaultConfig:{period:14},inputs:{period:{kind:`int`,min:2}},shortName:`TSF`,plots:[{key:`value`,title:`TSF`,color:0}]};read(e){return H(e,`period`,14,2)}pointAt(e,t,n){let r=Ya(e,t,n);return r?{value:r.end+r.slope}:null}},Ml=class extends B{descriptor={id:`demark`,name:`DeMark Projected Range`,placement:`overlay`,defaultConfig:{},shortName:`DeMark`,plots:[{key:`high`,title:`Projected high`,color:0,kind:`step`},{key:`low`,title:`Projected low`,color:1,kind:`step`}]};read(e){return null}pointAt(e,t){if(t===0)return null;let{open:n,high:r,low:i,close:a}=e[t-1],o=a>n?2*r+i+a:a<n?r+2*i+a:r+i+2*a;return{high:o/2-i,low:o/2-r}}},Nl=class extends I{descriptor={id:`rainbow`,name:`Moving Average Rainbow`,placement:`overlay`,defaultConfig:{first:10,step:10,count:10,exponential:0},shortName:`Rainbow`,inputs:{first:{kind:`int`,min:1},step:{kind:`int`,min:1},count:{kind:`int`,min:1,max:20},exponential:{kind:`int`,min:0,max:1}},plots:Array.from({length:20},(e,n)=>({key:`ma${n+1}`,title:`MA ${n+1}`,color:n%t.TC_SERIES_COLORS.length}))};calculate(e,t){let n=H(t,`first`,10,1),r=H(t,`step`,10,1),i=Math.min(20,H(t,`count`,10,1)),a=H(t,`exponential`,0,0)>=1?z:Ia,o=Fa(e),s=Array.from({length:i},(e,t)=>[`ma${t+1}`,a(o,n+t*r)]);return R(e,e.map((e,t)=>{let n={},r=!1;for(let[e,i]of s)i[t]!==void 0&&(n[e]=i[t],r=!0);return r?n:null}))}},Pl=.05,Fl=class{bodies=new Map;ranges=new Map;trends=new Map;constructor(e,t){this.data=e,this.period=t}open(e){return this.data[e].open}high(e){return this.data[e].high}low(e){return this.data[e].low}close(e){return this.data[e].close}body(e){return Math.abs(this.data[e].close-this.data[e].open)}range(e){return this.data[e].high-this.data[e].low}bodyTop(e){return Math.max(this.data[e].open,this.data[e].close)}bodyBottom(e){return Math.min(this.data[e].open,this.data[e].close)}mid(e){return(this.data[e].open+this.data[e].close)/2}upper(e){return this.data[e].high-this.bodyTop(e)}lower(e){return this.bodyBottom(e)-this.data[e].low}white(e){return this.data[e].close>this.data[e].open}black(e){return this.data[e].close<this.data[e].open}avgBody(e){let t=this.bodies.get(e);return t===void 0&&(t=this.averageBefore(e,e=>this.body(e)),this.bodies.set(e,t)),t}avgRange(e){let t=this.ranges.get(e);return t===void 0&&(t=this.averageBefore(e,e=>this.range(e)),this.ranges.set(e,t)),t}averageBefore(e,t){let n=Math.max(0,e-this.period);if(e<=n)return t(e);let r=0;for(let i=n;i<e;i++)r+=t(i);return r/(e-n)}bodyScale(e){return Math.max(this.avgBody(e),this.avgRange(e)*.25)}long(e,t=e){let n=this.bodyScale(t);return n>0&&this.body(e)>n}short(e,t=e){return this.body(e)<this.bodyScale(t)*.5}doji(e){return this.range(e)>0&&this.body(e)<=this.range(e)*.1}marubozu(e,t=e){return this.long(e,t)&&this.upper(e)<=this.range(e)*.05&&this.lower(e)<=this.range(e)*.05}same(e,t,n){return Math.abs(e-t)<=this.avgRange(n)*Pl}bodyGapUp(e,t){return this.bodyBottom(t)>this.bodyTop(e)}bodyGapDown(e,t){return this.bodyTop(t)<this.bodyBottom(e)}bodyInside(e,t){return this.bodyTop(t)<=this.bodyTop(e)&&this.bodyBottom(t)>=this.bodyBottom(e)&&this.body(t)<this.body(e)}trendBefore(e){let t=this.trends.get(e);return t===void 0&&(t=this.readTrend(e),this.trends.set(e,t)),t}readTrend(e){let t=e-1;if(t<this.period-1)return null;let n=0;for(let e=t-this.period+1;e<=t;e++)n+=this.close(e);let r=n/this.period,i=this.close(t),a=this.close(t-this.period+1);return i>r&&i>a?`up`:i<r&&i<a?`down`:null}};function U(e,t,n,r,i,a,o,s){return{info:Object.freeze({id:e,name:t,short:n,direction:r,kind:i,bars:a}),trend:o,test:s}}function Il(e,t){let n=e.range(t);return n>0&&n>=e.avgRange(t)*.5&&e.body(t)<=n*.35&&e.lower(t)>=2*Math.max(e.body(t),n*.05)&&e.upper(t)<=n*.1}function Ll(e,t){let n=e.range(t);return n>0&&n>=e.avgRange(t)*.5&&e.body(t)<=n*.35&&e.upper(t)>=2*Math.max(e.body(t),n*.05)&&e.lower(t)<=n*.1}var Rl=[U(`doji`,`Doji`,`Doji`,`neutral`,`indecision`,1,null,(e,t)=>e.doji(t)),U(`longLeggedDoji`,`Long-Legged Doji`,`LL Doji`,`neutral`,`indecision`,1,null,(e,t)=>e.doji(t)&&e.upper(t)>=e.range(t)*.3&&e.lower(t)>=e.range(t)*.3&&e.range(t)>e.avgRange(t)),U(`dragonflyDoji`,`Dragonfly Doji`,`Dragonfly`,`bullish`,`reversal`,1,`down`,(e,t)=>e.doji(t)&&e.upper(t)<=e.range(t)*.1&&e.lower(t)>=e.range(t)*.6),U(`gravestoneDoji`,`Gravestone Doji`,`Gravestone`,`bearish`,`reversal`,1,`up`,(e,t)=>e.doji(t)&&e.lower(t)<=e.range(t)*.1&&e.upper(t)>=e.range(t)*.6),U(`hammer`,`Hammer`,`Hammer`,`bullish`,`reversal`,1,`down`,Il),U(`hangingMan`,`Hanging Man`,`Hanging`,`bearish`,`reversal`,1,`up`,Il),U(`invertedHammer`,`Inverted Hammer`,`Inv Hammer`,`bullish`,`reversal`,1,`down`,Ll),U(`shootingStar`,`Shooting Star`,`Shooting`,`bearish`,`reversal`,1,`up`,Ll),U(`spinningTop`,`Spinning Top`,`Spinning`,`neutral`,`indecision`,1,null,(e,t)=>!e.doji(t)&&e.body(t)<=e.range(t)*.3&&e.upper(t)>e.body(t)&&e.lower(t)>e.body(t)),U(`bullishMarubozu`,`Bullish Marubozu`,`Marubozu`,`bullish`,`continuation`,1,null,(e,t)=>e.white(t)&&e.marubozu(t)),U(`bearishMarubozu`,`Bearish Marubozu`,`Marubozu`,`bearish`,`continuation`,1,null,(e,t)=>e.black(t)&&e.marubozu(t)),U(`bullishBeltHold`,`Bullish Belt Hold`,`Belt Hold`,`bullish`,`reversal`,1,`down`,(e,t)=>e.white(t)&&e.long(t)&&e.lower(t)<=e.range(t)*.05&&e.upper(t)>e.range(t)*.05),U(`bearishBeltHold`,`Bearish Belt Hold`,`Belt Hold`,`bearish`,`reversal`,1,`up`,(e,t)=>e.black(t)&&e.long(t)&&e.upper(t)<=e.range(t)*.05&&e.lower(t)>e.range(t)*.05)],zl=[U(`bullishEngulfing`,`Bullish Engulfing`,`Engulf`,`bullish`,`reversal`,2,`down`,(e,t)=>{let n=t-1;return e.black(n)&&e.white(t)&&e.open(t)<=e.close(n)&&e.close(t)>=e.open(n)&&e.body(t)>e.body(n)}),U(`bearishEngulfing`,`Bearish Engulfing`,`Engulf`,`bearish`,`reversal`,2,`up`,(e,t)=>{let n=t-1;return e.white(n)&&e.black(t)&&e.open(t)>=e.close(n)&&e.close(t)<=e.open(n)&&e.body(t)>e.body(n)}),U(`bullishHarami`,`Bullish Harami`,`Harami`,`bullish`,`reversal`,2,`down`,(e,t)=>e.black(t-1)&&e.long(t-1,t-1)&&!e.doji(t)&&e.bodyInside(t-1,t)&&e.body(t)<e.body(t-1)*.6),U(`bearishHarami`,`Bearish Harami`,`Harami`,`bearish`,`reversal`,2,`up`,(e,t)=>e.white(t-1)&&e.long(t-1,t-1)&&!e.doji(t)&&e.bodyInside(t-1,t)&&e.body(t)<e.body(t-1)*.6),U(`bullishHaramiCross`,`Bullish Harami Cross`,`Harami +`,`bullish`,`reversal`,2,`down`,(e,t)=>e.black(t-1)&&e.long(t-1,t-1)&&e.doji(t)&&e.bodyInside(t-1,t)),U(`bearishHaramiCross`,`Bearish Harami Cross`,`Harami +`,`bearish`,`reversal`,2,`up`,(e,t)=>e.white(t-1)&&e.long(t-1,t-1)&&e.doji(t)&&e.bodyInside(t-1,t)),U(`piercingLine`,`Piercing Line`,`Piercing`,`bullish`,`reversal`,2,`down`,(e,t)=>{let n=t-1;return e.black(n)&&e.long(n,n)&&e.white(t)&&e.open(t)<e.low(n)&&e.close(t)>e.mid(n)&&e.close(t)<e.open(n)}),U(`darkCloudCover`,`Dark Cloud Cover`,`Dark Cloud`,`bearish`,`reversal`,2,`up`,(e,t)=>{let n=t-1;return e.white(n)&&e.long(n,n)&&e.black(t)&&e.open(t)>e.high(n)&&e.close(t)<e.mid(n)&&e.close(t)>e.open(n)}),U(`tweezerBottom`,`Tweezer Bottom`,`Tweezer`,`bullish`,`reversal`,2,`down`,(e,t)=>e.black(t-1)&&e.white(t)&&e.same(e.low(t-1),e.low(t),t-1)),U(`tweezerTop`,`Tweezer Top`,`Tweezer`,`bearish`,`reversal`,2,`up`,(e,t)=>e.white(t-1)&&e.black(t)&&e.same(e.high(t-1),e.high(t),t-1)),U(`bullishKicking`,`Bullish Kicking`,`Kicking`,`bullish`,`reversal`,2,null,(e,t)=>e.black(t-1)&&e.marubozu(t-1,t-1)&&e.white(t)&&e.marubozu(t,t-1)&&e.low(t)>e.high(t-1)),U(`bearishKicking`,`Bearish Kicking`,`Kicking`,`bearish`,`reversal`,2,null,(e,t)=>e.white(t-1)&&e.marubozu(t-1,t-1)&&e.black(t)&&e.marubozu(t,t-1)&&e.high(t)<e.low(t-1)),U(`bullishCounterattack`,`Bullish Counterattack`,`Counter`,`bullish`,`reversal`,2,`down`,(e,t)=>e.black(t-1)&&e.long(t-1,t-1)&&e.white(t)&&e.long(t,t-1)&&e.same(e.close(t),e.close(t-1),t-1)),U(`bearishCounterattack`,`Bearish Counterattack`,`Counter`,`bearish`,`reversal`,2,`up`,(e,t)=>e.white(t-1)&&e.long(t-1,t-1)&&e.black(t)&&e.long(t,t-1)&&e.same(e.close(t),e.close(t-1),t-1)),U(`matchingLow`,`Matching Low`,`Match Low`,`bullish`,`reversal`,2,`down`,(e,t)=>e.black(t-1)&&e.long(t-1,t-1)&&e.black(t)&&e.same(e.close(t),e.close(t-1),t-1)),U(`homingPigeon`,`Homing Pigeon`,`Pigeon`,`bullish`,`reversal`,2,`down`,(e,t)=>e.black(t-1)&&e.long(t-1,t-1)&&e.black(t)&&e.short(t,t-1)&&e.bodyInside(t-1,t)),U(`onNeck`,`On Neck`,`On Neck`,`bearish`,`continuation`,2,`down`,(e,t)=>{let n=t-1;return e.black(n)&&e.long(n,n)&&e.white(t)&&e.open(t)<e.low(n)&&e.same(e.close(t),e.low(n),n)&&e.close(t)<e.close(n)}),U(`inNeck`,`In Neck`,`In Neck`,`bearish`,`continuation`,2,`down`,(e,t)=>{let n=t-1;return e.black(n)&&e.long(n,n)&&e.white(t)&&e.open(t)<e.low(n)&&e.close(t)>e.close(n)&&e.close(t)<=e.close(n)+e.body(n)*.1}),U(`thrusting`,`Thrusting`,`Thrusting`,`bearish`,`continuation`,2,`down`,(e,t)=>{let n=t-1;return e.black(n)&&e.long(n,n)&&e.white(t)&&e.open(t)<e.low(n)&&e.close(t)>e.close(n)+e.body(n)*.1&&e.close(t)<e.mid(n)}),U(`bullishSeparatingLines`,`Bullish Separating Lines`,`Separating`,`bullish`,`continuation`,2,`up`,(e,t)=>e.black(t-1)&&e.white(t)&&e.long(t,t-1)&&e.lower(t)<=e.range(t)*.05&&e.same(e.open(t),e.open(t-1),t-1)),U(`bearishSeparatingLines`,`Bearish Separating Lines`,`Separating`,`bearish`,`continuation`,2,`down`,(e,t)=>e.white(t-1)&&e.black(t)&&e.long(t,t-1)&&e.upper(t)<=e.range(t)*.05&&e.same(e.open(t),e.open(t-1),t-1))];function Bl(e,t){for(let n=t;n<t+3;n++)if(!e.white(n)||e.short(n,t)||e.upper(n)>e.body(n)*.25||n>t&&(e.close(n)<=e.close(n-1)||e.open(n)<e.open(n-1)||e.open(n)>e.close(n-1)))return!1;return!0}function Vl(e,t){for(let n=t;n<t+3;n++)if(!e.black(n)||e.short(n,t)||e.lower(n)>e.body(n)*.25||n>t&&(e.close(n)>=e.close(n-1)||e.open(n)>e.open(n-1)||e.open(n)<e.close(n-1)))return!1;return!0}function Hl(e,t,n,r){for(let i=t+1;i<=n;i++)if(r?e.close(i)>=e.close(i-1):e.close(i)<=e.close(i-1))return!1;return!0}function Ul(e,t,n,r,i){for(let a=n;a<=r;a++)if((i?!e.black(a):!e.white(a))||e.long(a,t)||e.high(a)>e.high(t)||e.low(a)<e.low(t))return!1;return!0}var Wl=[U(`morningStar`,`Morning Star`,`M. Star`,`bullish`,`reversal`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.long(n,n)&&e.short(r,n)&&!e.doji(r)&&e.bodyGapDown(n,r)&&e.white(t)&&e.close(t)>e.mid(n)}),U(`eveningStar`,`Evening Star`,`E. Star`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.long(n,n)&&e.short(r,n)&&!e.doji(r)&&e.bodyGapUp(n,r)&&e.black(t)&&e.close(t)<e.mid(n)}),U(`morningDojiStar`,`Morning Doji Star`,`M. Doji`,`bullish`,`reversal`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.long(n,n)&&e.doji(r)&&e.bodyGapDown(n,r)&&e.white(t)&&e.close(t)>e.mid(n)}),U(`eveningDojiStar`,`Evening Doji Star`,`E. Doji`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.long(n,n)&&e.doji(r)&&e.bodyGapUp(n,r)&&e.black(t)&&e.close(t)<e.mid(n)}),U(`bullishAbandonedBaby`,`Bullish Abandoned Baby`,`Abandoned`,`bullish`,`reversal`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.long(n,n)&&e.doji(r)&&e.high(r)<e.low(n)&&e.white(t)&&!e.short(t,n)&&e.low(t)>e.high(r)}),U(`bearishAbandonedBaby`,`Bearish Abandoned Baby`,`Abandoned`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.long(n,n)&&e.doji(r)&&e.low(r)>e.high(n)&&e.black(t)&&!e.short(t,n)&&e.high(t)<e.low(r)}),U(`threeWhiteSoldiers`,`Three White Soldiers`,`3 Soldiers`,`bullish`,`reversal`,3,null,(e,t)=>Bl(e,t-2)),U(`threeBlackCrows`,`Three Black Crows`,`3 Crows`,`bearish`,`reversal`,3,null,(e,t)=>Vl(e,t-2)),U(`threeInsideUp`,`Three Inside Up`,`3 Inside`,`bullish`,`reversal`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.long(n,n)&&e.white(r)&&e.bodyInside(n,r)&&e.white(t)&&e.close(t)>e.open(n)}),U(`threeInsideDown`,`Three Inside Down`,`3 Inside`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.long(n,n)&&e.black(r)&&e.bodyInside(n,r)&&e.black(t)&&e.close(t)<e.open(n)}),U(`threeOutsideUp`,`Three Outside Up`,`3 Outside`,`bullish`,`reversal`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.white(r)&&e.open(r)<=e.close(n)&&e.close(r)>=e.open(n)&&e.body(r)>e.body(n)&&e.white(t)&&e.close(t)>e.close(r)}),U(`threeOutsideDown`,`Three Outside Down`,`3 Outside`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.black(r)&&e.open(r)>=e.close(n)&&e.close(r)<=e.open(n)&&e.body(r)>e.body(n)&&e.black(t)&&e.close(t)<e.close(r)}),U(`upsideGapTwoCrows`,`Upside Gap Two Crows`,`2 Crows Gap`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.long(n,n)&&e.black(r)&&e.short(r,n)&&e.bodyGapUp(n,r)&&e.black(t)&&e.open(t)>e.open(r)&&e.close(t)<e.close(r)&&e.close(t)>e.close(n)}),U(`twoCrows`,`Two Crows`,`2 Crows`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.long(n,n)&&e.black(r)&&e.bodyGapUp(n,r)&&e.black(t)&&e.open(t)<e.open(r)&&e.open(t)>e.close(r)&&e.close(t)<e.close(n)&&e.close(t)>e.open(n)}),U(`bullishTriStar`,`Bullish Tri-Star`,`Tri-Star`,`bullish`,`reversal`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.doji(n)&&e.doji(r)&&e.doji(t)&&e.bodyGapDown(n,r)&&e.bodyGapUp(r,t)}),U(`bearishTriStar`,`Bearish Tri-Star`,`Tri-Star`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.doji(n)&&e.doji(r)&&e.doji(t)&&e.bodyGapUp(n,r)&&e.bodyGapDown(r,t)}),U(`upsideTasukiGap`,`Upside Tasuki Gap`,`Tasuki`,`bullish`,`continuation`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.white(r)&&e.low(r)>e.high(n)&&e.black(t)&&e.open(t)<e.close(r)&&e.open(t)>e.open(r)&&e.close(t)<e.low(r)&&e.close(t)>e.high(n)}),U(`downsideTasukiGap`,`Downside Tasuki Gap`,`Tasuki`,`bearish`,`continuation`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.black(r)&&e.high(r)<e.low(n)&&e.white(t)&&e.open(t)>e.close(r)&&e.open(t)<e.open(r)&&e.close(t)>e.high(r)&&e.close(t)<e.low(n)}),U(`stickSandwich`,`Stick Sandwich`,`Sandwich`,`bullish`,`reversal`,3,`down`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.white(r)&&e.low(r)>e.close(n)&&e.black(t)&&e.same(e.close(t),e.close(n),n)}),U(`advanceBlock`,`Advance Block`,`Adv Block`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.white(n)&&e.long(n,n)&&e.white(r)&&e.white(t)&&e.close(r)>e.close(n)&&e.close(t)>e.close(r)&&e.open(r)>e.open(n)&&e.open(r)<=e.close(n)&&e.open(t)>e.open(r)&&e.open(t)<=e.close(r)&&e.body(t)<e.body(r)&&e.body(r)<e.body(n)&&e.upper(t)>e.upper(n)}),U(`identicalThreeCrows`,`Identical Three Crows`,`Ident Crows`,`bearish`,`reversal`,3,`up`,(e,t)=>{let n=t-2,r=t-1;return e.black(n)&&e.black(r)&&e.black(t)&&e.close(r)<e.close(n)&&e.close(t)<e.close(r)&&e.same(e.open(r),e.close(n),n)&&e.same(e.open(t),e.close(r),n)&&e.lower(n)<=e.body(n)*.25&&e.lower(r)<=e.body(r)*.25&&e.lower(t)<=e.body(t)*.25})],Gl=[U(`bullishThreeLineStrike`,`Bullish Three-Line Strike`,`Strike`,`bullish`,`continuation`,4,`up`,(e,t)=>{let n=t-3;return e.white(n)&&e.white(n+1)&&e.white(n+2)&&Hl(e,n,n+2,!1)&&e.open(n+1)>=e.open(n)&&e.open(n+1)<=e.close(n)&&e.open(n+2)>=e.open(n+1)&&e.open(n+2)<=e.close(n+1)&&e.black(t)&&e.open(t)>e.close(n+2)&&e.close(t)<e.open(n)}),U(`bearishThreeLineStrike`,`Bearish Three-Line Strike`,`Strike`,`bearish`,`continuation`,4,`down`,(e,t)=>{let n=t-3;return e.black(n)&&e.black(n+1)&&e.black(n+2)&&Hl(e,n,n+2,!0)&&e.open(n+1)<=e.open(n)&&e.open(n+1)>=e.close(n)&&e.open(n+2)<=e.open(n+1)&&e.open(n+2)>=e.close(n+1)&&e.white(t)&&e.open(t)<e.close(n+2)&&e.close(t)>e.open(n)}),U(`risingThreeMethods`,`Rising Three Methods`,`Rising 3`,`bullish`,`continuation`,5,`up`,(e,t)=>{let n=t-4;return e.white(n)&&e.long(n,n)&&Ul(e,n,n+1,n+3,!0)&&Hl(e,n+1,n+3,!0)&&e.white(t)&&e.long(t,n)&&e.open(t)>e.close(t-1)&&e.close(t)>e.close(n)}),U(`fallingThreeMethods`,`Falling Three Methods`,`Falling 3`,`bearish`,`continuation`,5,`down`,(e,t)=>{let n=t-4;return e.black(n)&&e.long(n,n)&&Ul(e,n,n+1,n+3,!1)&&Hl(e,n+1,n+3,!1)&&e.black(t)&&e.long(t,n)&&e.open(t)<e.close(t-1)&&e.close(t)<e.close(n)}),U(`matHold`,`Mat Hold`,`Mat Hold`,`bullish`,`continuation`,5,`up`,(e,t)=>{let n=t-4;if(!(e.white(n)&&e.long(n,n)&&e.black(n+1)&&e.short(n+1,n)&&e.bodyGapUp(n,n+1)))return!1;for(let t=n+1;t<=n+3;t++)if(e.long(t,n)||e.bodyBottom(t)<e.mid(n))return!1;let r=Math.max(e.high(n+1),e.high(n+2),e.high(n+3));return e.close(n+3)<e.close(n+1)&&e.white(t)&&e.open(t)>e.close(t-1)&&e.close(t)>r}),U(`bullishBreakaway`,`Bullish Breakaway`,`Breakaway`,`bullish`,`reversal`,5,`down`,(e,t)=>{let n=t-4;return e.black(n)&&e.long(n,n)&&e.black(n+1)&&e.bodyGapDown(n,n+1)&&e.close(n+2)<e.close(n+1)&&e.close(n+3)<e.close(n+2)&&e.black(n+3)&&e.white(t)&&e.close(t)>e.open(n+1)&&e.close(t)<e.close(n)}),U(`bearishBreakaway`,`Bearish Breakaway`,`Breakaway`,`bearish`,`reversal`,5,`up`,(e,t)=>{let n=t-4;return e.white(n)&&e.long(n,n)&&e.white(n+1)&&e.bodyGapUp(n,n+1)&&e.close(n+2)>e.close(n+1)&&e.close(n+3)>e.close(n+2)&&e.white(n+3)&&e.black(t)&&e.close(t)<e.open(n+1)&&e.close(t)>e.close(n)}),U(`concealingBabySwallow`,`Concealing Baby Swallow`,`Swallow`,`bullish`,`reversal`,4,`down`,(e,t)=>{let n=t-3;return e.black(n)&&e.marubozu(n,n)&&e.black(n+1)&&e.marubozu(n+1,n)&&e.black(n+2)&&e.open(n+2)<e.close(n+1)&&e.high(n+2)>e.close(n+1)&&e.black(t)&&e.open(t)>e.high(n+2)&&e.close(t)<e.low(n+2)}),U(`ladderBottom`,`Ladder Bottom`,`Ladder`,`bullish`,`reversal`,5,`down`,(e,t)=>{let n=t-4;for(let t=n;t<=n+3;t++)if(!e.black(t))return!1;for(let t=n+1;t<=n+2;t++)if(e.open(t)>=e.open(t-1)||e.close(t)>=e.close(t-1))return!1;return e.upper(n+3)>e.body(n+3)&&e.white(t)&&e.open(t)>e.open(n+3)&&e.close(t)>e.high(n+3)})],Kl=[...Rl,...zl,...Wl,...Gl],ql=Kl.map(e=>e.info);function Jl(e){let t=e.trendPeriod;return t!==void 0&&Number.isFinite(t)?Math.max(2,Math.floor(t)):10}function Yl(e){if(!e.patterns)return Kl;let t=new Set(e.patterns);return Kl.filter(e=>t.has(e.info.id))}function Xl(e,t,n){let r=[];for(let i of n){let n=t-i.info.bars+1;n<0||i.trend&&e.trendBefore(n)!==i.trend||i.test(e,t)&&r.push(i)}return r}function Zl(e,t={}){let n=new Fl(e,Jl(t)),r=Yl(t),i=[],a=t.from!==void 0&&Number.isFinite(t.from)?Math.max(0,Math.floor(t.from)):0;for(let t=a;t<e.length;t++)for(let a of Xl(n,t,r))i.push({index:t,time:e[t].time,pattern:a.info});return i}function Ql(e={}){return Yl(e)}var $l=6,eu=4,tu=12,nu=class extends B{descriptor={id:`candlepatterns`,name:`Candlestick Patterns`,placement:`overlay`,defaultConfig:{trendPeriod:10,reversal:1,continuation:1,indecision:0},shortName:`Patterns`,inputs:{trendPeriod:{kind:`int`,min:2},reversal:{kind:`int`,min:0,max:1},continuation:{kind:`int`,min:0,max:1},indecision:{kind:`int`,min:0,max:1}},plots:[{key:`bull`,title:`Bullish`,color:3,kind:`dots`},{key:`bear`,title:`Bearish`,color:4,kind:`dots`},{key:`neutral`,title:`Indecision`,color:1,kind:`dots`}]};read(e){let t=new Set;return H(e,`reversal`,1,0)>=1&&t.add(`reversal`),H(e,`continuation`,1,0)>=1&&t.add(`continuation`),H(e,`indecision`,0,0)>=1&&t.add(`indecision`),{trendPeriod:H(e,`trendPeriod`,10,2),defs:Ql().filter(e=>t.has(e.info.kind))}}pointAt(e,t,{trendPeriod:n,defs:r}){let i=Xl(new Fl(e,n),t,r);if(i.length===0)return null;let a=i[0];for(let e of i)e.info.bars>=a.info.bars&&(a=e);let o=e[t],s={code:ql.indexOf(a.info),count:i.length};return a.info.direction===`bullish`?s.bull=o.low:a.info.direction===`bearish`?s.bear=o.high:s.neutral=o.high,s}render(t,n,r,i){let a=n.series;if(!a)return;let o=Math.max(0,Math.floor(r.visibleRange.from)),s=Math.min(a.length-1,Math.ceil(r.visibleRange.to)),c=r.barWidth+r.barSpacing>=tu,{chartRect:l}=r,u=l.y+10,d=l.y+l.height-10,f=e=>i.plots?.[e]?.visible!==!1;t.save(),t.globalAlpha=i.opacity,t.font=`10px sans-serif`,t.textAlign=`center`;let p=-1/0,m=-1/0;for(let n=o;n<=s;n++){let o=a[n];if(!o)continue;let s=e.b(n,r),l=ql[o.code??-1]?.short??``;if(o.bull!==void 0&&f(`bull`)){let n=e.T(o.bull,r)+eu;t.fillStyle=i.colors[3]??i.colors[0],ru(t,s,n,`up`),c&&l&&(m=iu(t,l,s,Math.min(d,n+$l+2),`top`,m))}else if(o.bear!==void 0&&f(`bear`)){let n=e.T(o.bear,r)-eu;t.fillStyle=i.colors[4]??i.colors[0],ru(t,s,n,`down`),c&&l&&(p=iu(t,l,s,Math.max(u,n-$l-2),`bottom`,p))}else if(o.neutral!==void 0&&f(`neutral`)){let n=e.T(o.neutral,r)-eu-$l/2;t.fillStyle=i.colors[1]??i.colors[0],t.beginPath(),t.arc(s,n,$l/2-1,0,Math.PI*2),t.fill(),c&&l&&(p=iu(t,l,s,Math.max(u,n-$l/2-2),`bottom`,p))}}t.restore()}};function ru(e,t,n,r){let i=$l/2;e.beginPath(),r===`up`?(e.moveTo(t,n),e.lineTo(t-i,n+$l),e.lineTo(t+i,n+$l)):(e.moveTo(t,n),e.lineTo(t-i,n-$l),e.lineTo(t+i,n-$l)),e.closePath(),e.fill()}function iu(e,t,n,r,i,a){let o=e.measureText(t).width/2;return n-o<a+2?a:(e.textBaseline=i,e.fillText(t,n,r),n+o)}var au=500,ou=class extends I{descriptor={id:`machannel`,name:`Moving Average Channel`,placement:`overlay`,defaultConfig:{upperLength:20,lowerLength:20,upperOffset:0,lowerOffset:0},shortName:`MA Channel`,inputs:{upperLength:{kind:`int`,min:1},lowerLength:{kind:`int`,min:1},upperOffset:{kind:`int`,min:-au,max:au},lowerOffset:{kind:`int`,min:-au,max:au}},fills:[{between:[`upper`,`lower`],color:0,opacity:.08}],plots:[{key:`upper`,title:`Upper`,color:0},{key:`lower`,title:`Lower`,color:1}]};calculate(e,t){let n=cu(Ia(e.map(e=>e.high),H(t,`upperLength`,20,1)),su(t,`upperOffset`)),r=cu(Ia(e.map(e=>e.low),H(t,`lowerLength`,20,1)),su(t,`lowerOffset`));return R(e,n.map((e,t)=>{let n=r[t];return e===void 0&&n===void 0?null:{...e===void 0?{}:{upper:e},...n===void 0?{}:{lower:n}}}))}};function su(e,t){let n=Number(e.params[t]??0);return Number.isFinite(n)?Math.max(-au,Math.min(au,Math.round(n))):0}function cu(e,t){return e.map((n,r)=>e[r-t])}var lu=500,uu=class extends B{descriptor={id:`hamming`,name:`Moving Average Hamming`,placement:`overlay`,defaultConfig:{period:10,source:`close`},shortName:`HMA (Hamming)`,inputs:{period:{kind:`int`,min:2,max:lu},source:{source:!0}},plots:[{key:`value`,title:`MA`,color:0}]};read(e){let t=Math.min(lu,H(e,`period`,10,2)),n=Array.from({length:t},(e,n)=>.54-.46*Math.cos(2*Math.PI*n/(t-1)));return{weights:n,total:n.reduce((e,t)=>e+t,0)}}pointAt(e,t,{weights:n,total:r}){let i=t-n.length+1;if(i<0)return null;let a=0;for(let t=0;t<n.length;t++)a+=n[t]*e[i+t].close;return{value:a/r}}},du=[`sma`,`ema`,`wma`];function fu(e,t,n){return e===`ema`?z(t,n):e===`wma`?Ra(t,n):Ia(t,n)}var pu=class extends I{calculate(e,t){let n=du.includes(t.params.type)?t.params.type:`sma`,r=Fa(e),i=this.lengths.map(([e,i])=>fu(n,r,H(t,e,i,1)));return R(e,e.map((e,t)=>{let n={};return i.forEach((e,r)=>{let i=e[t];i!==void 0&&(n[`ma${r+1}`]=i)}),Object.keys(n).length>0?n:null}))}},mu=class extends pu{lengths=[[`first`,20],[`second`,50]];descriptor={id:`madouble`,name:`Moving Average Double`,placement:`overlay`,defaultConfig:{first:20,second:50,type:`sma`,source:`close`},shortName:`MA x2`,inputs:{first:{kind:`int`,min:1},second:{kind:`int`,min:1},type:{options:du},source:{source:!0}},plots:[{key:`ma1`,title:`MA 1`,color:0},{key:`ma2`,title:`MA 2`,color:1}]}},hu=class extends pu{lengths=[[`first`,10],[`second`,20],[`third`,50]];descriptor={id:`matriple`,name:`Moving Average Triple`,placement:`overlay`,defaultConfig:{first:10,second:20,third:50,type:`sma`,source:`close`},shortName:`MA x3`,inputs:{first:{kind:`int`,min:1},second:{kind:`int`,min:1},third:{kind:`int`,min:1},type:{options:du},source:{source:!0}},plots:[{key:`ma1`,title:`MA 1`,color:0},{key:`ma2`,title:`MA 2`,color:1},{key:`ma3`,title:`MA 3`,color:2}]}},gu=class extends I{descriptor={id:`volindex`,name:`Volatility Index`,placement:`overlay`,defaultConfig:{period:7,mult:3},shortName:`VI`,inputs:{period:{kind:`int`,min:1},mult:{kind:`number`,label:`ATR multiple`,min:.1,step:.1}},plots:[{key:`sar`,title:`Stop`,color:0,kind:`dots`,tone:{field:`long`},downColor:1}]};calculate(e,t){let n=H(t,`period`,7,1),r=Math.max(.1,V(t,`mult`,3)),i=za(Va(e),n),a=Array(e.length).fill(null),o=null,s=0;for(let t=0;t<e.length;t++){let n=i[t];if(n===void 0)continue;let c=e[t].close,l=n*r;o===null?(o=c>=e[0].close,s=c):o?(s=Math.max(s,c),c<s-l&&(o=!1,s=c)):(s=Math.min(s,c),c>s+l&&(o=!0,s=c)),a[t]={sar:o?s-l:s+l,long:+!!o}}return R(e,a)}},_u=class extends I{descriptor={id:`asi`,name:`Accumulative Swing Index`,placement:`panel`,defaultConfig:{limit:10},shortName:`ASI`,inputs:{limit:{kind:`number`,label:`Limit move`,min:1e-4,step:.1}},plots:[{key:`value`,title:`ASI`,color:0}],scale:{zero:!0}};calculate(e,t){let n=Math.max(1e-9,V(t,`limit`,10)),r=Array(e.length).fill(null),i=0;for(let t=1;t<e.length;t++)i+=vu(e[t-1],e[t],n),r[t]={value:i};return R(e,r)}};function vu(e,t,n){let r=Math.abs(t.high-e.close),i=Math.abs(t.low-e.close),a=t.high-t.low,o=Math.abs(e.close-e.open),s;return s=r>=i&&r>=a?r-.5*i+.25*o:i>=r&&i>=a?i-.5*r+.25*o:a+.25*o,s===0?0:50*(t.close-e.close+.5*(t.close-t.open)+.25*(e.close-e.open))/s*(Math.max(r,i)/n)}var yu=class extends B{descriptor={id:`advdecline`,name:`Advance/Decline`,placement:`panel`,defaultConfig:{length:10},shortName:`A/D Ratio`,inputs:{length:{kind:`int`,min:1}},plots:[{key:`value`,title:`Ratio`,color:0}],scale:{min:0}};read(e){return{length:H(e,`length`,10,1)}}pointAt(e,t,{length:n}){if(t<n-1)return null;let r=0,i=0;for(let a=t-n+1;a<=t;a++)e[a].close>e[a].open?r++:e[a].close<e[a].open&&i++;return{value:i===0?r:r/i}}},bu=class extends B{descriptor={id:`majority`,name:`Majority Rule`,placement:`panel`,defaultConfig:{period:14},shortName:`Majority`,inputs:{period:{kind:`int`,min:1}},plots:[{key:`value`,title:`Majority`,color:0}],scale:{min:0,max:100},levels:[50]};read(e){return{period:H(e,`period`,14,1)}}pointAt(e,t,{period:n}){if(t<n)return null;let r=0;for(let i=t-n+1;i<=t;i++)e[i].close>e[i-1].close&&r++;return{value:100*r/n}}},xu=34,Su=30,Cu=class extends I{descriptor={id:`chopzone`,name:`Chop Zone`,placement:`panel`,defaultConfig:{},shortName:`Chop Zone`,plots:[{key:`angle`,title:`Angle`,color:0,kind:`histogram`}],scale:{zero:!0}};calculate(e,t){let n=z(Fa(e),xu),r=Array(e.length).fill(null);for(let t=1;t<e.length;t++){let i=n[t],a=n[t-1],o=Ka(e,t,Su),s=qa(e,t,Su);if(i===void 0||a===void 0||o===void 0||s===void 0||o===s)continue;let c=e[t],l=(c.high+c.low+c.close)/3;if(!(l>0&&s>0))continue;let u=(i-a)/l*(25/(o-s)*s);r[t]={angle:Math.atan(u)*180/Math.PI}}return R(e,r)}render(t,n,r,i){if(i.plots?.angle?.visible===!1)return;let a=n.series;if(!a)return;let{from:o,to:s}=r.visibleRange,c=e.T(0,r),l=[];for(let t=o;t<=s&&t<a.length;t++){let n=a[t]?.angle;n!==void 0&&l.push({x:e.b(t,r),y:e.T(n,r),baseY:c,color:wu(n)})}this.drawHistogram(t,l,Math.max(1,r.barWidth))}};function wu(e){return e>=5?`#26C6DA`:e>=3.57?`#43A047`:e>=2.14?`#A5D6A7`:e>=.71?`#009688`:e<=-5?`#D50000`:e<=-3.57?`#E91E63`:e<=-2.14?`#FF6D00`:e<=-.71?`#FFB74D`:`#FDD835`}var Tu=class extends I{descriptor={id:`smiergodic`,name:`SMI Ergodic`,placement:`panel`,defaultConfig:{short:5,long:20,signal:5,source:`close`},shortName:`SMIIO`,inputs:{short:{kind:`int`,min:1},long:{kind:`int`,min:1},signal:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`oscillator`,title:`Oscillator`,color:2,kind:`histogram`,tone:`sign`,downColor:3},{key:`indicator`,title:`Indicator`,color:0},{key:`signal`,title:`Signal`,color:1}],scale:{zero:!0}};calculate(e,t){let n=H(t,`short`,5,1),r=H(t,`long`,20,1),i=e.map((t,n)=>n===0?void 0:t.close-e[n-1].close),a=z(z(i,r),n),o=z(z(i.map(e=>e===void 0?void 0:Math.abs(e)),r),n),s=a.map((e,t)=>e===void 0||!o[t]?void 0:e/o[t]),c=z(s,H(t,`signal`,5,1));return R(e,s.map((e,t)=>{if(e===void 0)return null;let n=c[t];return n===void 0?{indicator:e}:{indicator:e,signal:n,oscillator:e-n}}))}},Eu=class extends I{descriptor={id:`po`,name:`Price Oscillator`,placement:`panel`,defaultConfig:{short:10,long:21,source:`close`},shortName:`PO`,inputs:{short:{kind:`int`,min:1},long:{kind:`int`,min:1},source:{source:!0}},plots:[{key:`value`,title:`PO`,color:0}],scale:{zero:!0}};calculate(e,t){let n=Fa(e),r=Ia(n,H(t,`short`,10,1)),i=Ia(n,H(t,`long`,21,1));return R(e,Wa(r.map((e,t)=>e===void 0||i[t]===void 0?void 0:e-i[t])))}},Du=e=>({period:H(e,`period`,10,1),annual:Math.max(1,V(e,`annual`,365))}),Ou={period:{kind:`int`,min:1},annual:{kind:`number`,label:`Bars per year`,min:1}},ku=class extends B{descriptor={id:`volohlc`,name:`Volatility O-H-L-C`,placement:`panel`,defaultConfig:{period:10,annual:365},shortName:`Vol OHLC`,inputs:Ou,plots:[{key:`value`,title:`Volatility`,color:0}],scale:{min:0}};read(e){return Du(e)}pointAt(e,t,{period:n,annual:r}){if(t<n-1)return null;let i=0;for(let r=t-n+1;r<=t;r++){let{open:t,high:n,low:a,close:o}=e[r];if(!(t>0&&n>0&&a>0&&o>0))return null;i+=.5*Math.log(n/a)**2-(2*Math.LN2-1)*Math.log(o/t)**2}return{value:100*Math.sqrt(Math.max(0,i/n*r))}}},Au=class extends B{descriptor={id:`volzt`,name:`Volatility Zero Trend Close-to-Close`,placement:`panel`,defaultConfig:{period:10,annual:365},shortName:`Vol ZT`,inputs:Ou,plots:[{key:`value`,title:`Volatility`,color:0}],scale:{min:0}};read(e){return Du(e)}pointAt(e,t,{period:n,annual:r}){if(t<n)return null;let i=0;for(let r=t-n+1;r<=t;r++){let t=e[r-1].close,n=e[r].close;if(!(t>0&&n>0))return null;i+=Math.log(n/t)**2}return{value:100*Math.sqrt(i/n*r)}}},ju=[()=>new Fo,()=>new Io,()=>new Lo,()=>new Uo,()=>new Ko,()=>new qo,()=>new Jo,()=>new Yo,()=>new Xo,()=>new Qo,()=>new es,()=>new ts,()=>new ns,()=>new rs,()=>new os,()=>new ss,()=>new cs,()=>new ls,()=>new ds,()=>new fs,()=>new ps,()=>new _s,()=>new bs,()=>new xs,()=>new Ss,()=>new Cs,()=>new ws,()=>new Ts,()=>new Es,()=>new Ds,()=>new Os,()=>new ks,()=>new As,()=>new js,()=>new Ms,()=>new vc,()=>new xc,()=>new Sc,()=>new Cc,()=>new vs,()=>new ys,()=>new Ns,()=>new Ps,()=>new Fs,()=>new Is,()=>new Rs,()=>new zs,()=>new Vs,()=>new Hs,()=>new Gs,()=>new Ks,()=>new Js,()=>new Ys,()=>new Xs,()=>new Zs,()=>new Qs,()=>new $s,()=>new ec,()=>new nc,()=>new rc,()=>new ic,()=>new ac,()=>new oc,()=>new sc,()=>new uc,()=>new fc,()=>new mc,()=>new hc,()=>new gc,()=>new _c,()=>new wc,()=>new Tc,()=>new Ec,()=>new Dc,()=>new Oc,()=>new kc,()=>new Mc,()=>new Pc,()=>new Fc,()=>new Rc,()=>new zc,()=>new Bc,()=>new Vc,()=>new Hc,()=>new Wc,()=>new qc,()=>new Jc,()=>new Yc,()=>new Xc,()=>new Zc,()=>new Qc,()=>new $c,()=>new el,()=>new rl,()=>new il,()=>new ol,()=>new sl,()=>new cl,()=>new ou,()=>new uu,()=>new mu,()=>new hu,()=>new gu,()=>new _u,()=>new yu,()=>new bu,()=>new Cu,()=>new Tu,()=>new Eu,()=>new ku,()=>new Au,()=>new ul,()=>new dl,()=>new fl,()=>new pl,()=>new ml,()=>new hl,()=>new gl,()=>new _l,()=>new yl,()=>new Sl,()=>new Cl,()=>new wl,()=>new Tl,()=>new El,()=>new Dl,()=>new Ol,()=>new kl,()=>new Al,()=>new jl,()=>new ll,()=>new Ml,()=>new Nl,()=>new nu];function Mu(e){for(let t of ju){let n=t();Pa.add(n),e.register(n)}}var Nu=[`movingAverages`,`trend`,`oscillators`,`volatility`,`volume`,`bands`,`patterns`,`other`],Pu=new Map(Object.entries({movingAverages:[`sma`,`ema`,`wma`,`vwma`,`hma`,`tema`,`dema`,`smma`,`alma`,`kama`,`lsma`,`mcginley`,`mtfma`,`macross`,`gmma`,`maribbon`,`hamming`,`madouble`,`matriple`,`rainbow`,`alligator`,`tsf`],trend:[`ichimoku`,`psar`,`supertrend`,`chandelier`,`cks`,`volindex`,`adx`,`aroon`,`vortex`,`chop`,`chopzone`,`vhf`,`trendstrength`,`lrslope`,`rsquared`,`rwi`,`majority`,`asi`],oscillators:`rsi.macd.stochastic.williamsR.cci.roc.tsi.ao.uo.crsi.coppock.kst.elderray.stc.fisher.dpo.bop.cmo.trix.rvi.stochrsi.ppo.ac.rmi.disparity.qstick.pgo.bbpb.mom.smi.smiergodic.po.psy.newpsy.sonar.binarywave.sroc.abratio.advdecline`.split(`.`),volatility:[`atr`,`stddev`,`chaikinvol`,`bbw`,`hv`,`ulcer`,`rvix`,`stderror`,`adr`,`volohlc`,`volzt`,`sigma`,`tr`,`massindex`],volume:[`vwap`,`avwap`,`svwap`,`volumeProfile`,`obv`,`mfi`,`cmf`,`ad`,`vroc`,`chaikinOsc`,`voldelta`,`fi`,`kvo`,`emv`,`pvt`,`wad`,`vo`,`netvolume`,`vr`,`nvi`,`pvi`,`iii`,`volpct`,`volchange`,`tradevalue`],bands:[`bb`,`keltner`,`donchian`,`envelope`,`lrc`,`seb`,`machannel`],patterns:[`pivots`,`zigzag`,`fractals`,`candlepatterns`,`demark`,`avgprice`,`medprice`,`typprice`,`wclose`]}).flatMap(([e,t])=>t.map(t=>[t,e])));function Fu(e){return e.category??Pu.get(e.id)??`other`}var Iu=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,Lu=1,Ru=.1;function zu(e,t){return t?.kind?t.kind:t?.source?`source`:t?.options?`choice`:typeof e==`boolean`?`boolean`:typeof e==`number`?`number`:typeof e==`string`&&Iu.test(e)?`color`:`text`}function Bu(e){return Object.entries(e.defaultConfig).map(([t,n])=>{let r=e.inputs?.[t],i=zu(n,r),a={name:t,kind:i,default:n};return r?.label!==void 0&&(a.label=r.label),r?.min!==void 0&&(a.min=r.min),r?.max!==void 0&&(a.max=r.max),i===`int`&&(a.step=r?.step??Lu),i===`number`&&(a.step=r?.step??(Number.isInteger(n)?Lu:Ru)),i===`choice`&&r?.options&&(a.options=r.options),a})}function Vu(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.requestId==`number`?t.type===`result`||t.type===`pong`||t.type===`error`:!1}var Hu=class{worker;fallbackPlugins;timeoutMs;nextRequestId=1;pending=new Map;messageHandler;constructor(e,t={}){this.worker=e,this.fallbackPlugins=t.fallbackPlugins??new Map,this.timeoutMs=t.timeoutMs??3e4,this.messageHandler=e=>this.handleMessage(e),this.worker&&(this.worker.addEventListener(`message`,this.messageHandler),this.worker.addEventListener(`error`,this.messageHandler))}hasWorker(){return this.worker!==null}registerFallbackPlugin(e){this.fallbackPlugins.set(e.descriptor.id,e)}async calculate(e,t,n){if(!this.worker){let r=this.fallbackPlugins.get(e);if(!r)throw Error(`Unknown indicator: ${e}`);return r.calculate(n,t)}let r=this.nextRequestId++,i=co(n),a={type:`calculate`,bars:i,jobs:[{requestId:r,indicatorId:e,config:t}]},o=i.time.slice();return new Promise((t,n)=>{let s={resolve:t,reject:n,timer:null,times:o};this.timeoutMs>0&&(s.timer=setTimeout(()=>{this.pending.delete(r),n(Error(`Indicator worker timeout (${this.timeoutMs}ms): ${e}`))},this.timeoutMs)),this.pending.set(r,s),this.worker.postMessage(a,uo(i))})}ping(){if(!this.worker)return Promise.resolve();let e=this.nextRequestId++;return new Promise((t,n)=>{let r={resolve:()=>t(),reject:n,timer:this.timeoutMs>0?setTimeout(()=>{this.pending.delete(e),n(Error(`Indicator worker ping timeout`))},this.timeoutMs):null};this.pending.set(e,r),this.worker.postMessage({type:`ping`,requestId:e})})}terminate(){this.worker&&=(this.worker.removeEventListener(`message`,this.messageHandler),this.worker.removeEventListener(`error`,this.messageHandler),this.worker.terminate(),null);for(let e of this.pending.values())e.timer&&clearTimeout(e.timer),e.reject(Error(`Indicator worker terminated`));this.pending.clear()}handleMessage(e){let t=e.data;if(t!==void 0){if(!Vu(t))return;this.dispatchResponse(t);return}let n=e.message??`Indicator worker error`;for(let[e,t]of this.pending)t.timer&&clearTimeout(t.timer),t.reject(Error(n)),this.pending.delete(e)}dispatchResponse(e){let t=this.pending.get(e.requestId);if(t){if(this.pending.delete(e.requestId),t.timer&&clearTimeout(t.timer),e.type===`error`){t.reject(Error(e.message));return}if(e.type===`pong`){t.resolve(void 0);return}t.resolve(bo(e.output,t.times??[]))}}};function Uu(){return typeof Worker>`u`?Promise.reject(Error(`Web Workers are not available here`)):Promise.resolve().then(()=>require(`./indicator.worker-g0us81yM.cjs`)).then(({default:e})=>new e({name:`tradecanvas-indicators`}))}function Wu(){if(typeof Worker>`u`)throw Error(`Web Workers are not available here`);return Uu()}var Gu=class{state=`starting`;worker=null;outbox=[];jobs=new Map;batch=null;nextId=1;pingId=0;onMessage=e=>this.receive(e.data);onError=e=>this.fail(Error(e.message||`Indicator worker error`));constructor(e){let t;try{t=e()}catch(e){this.fail(Ku(e));return}t instanceof Promise?t.then(e=>this.attach(e),e=>this.fail(Ku(e))):this.attach(t)}get usable(){return this.state===`starting`||this.state===`ready`}get ready(){return this.state===`ready`}submit(e,t){if(!this.usable)return null;let n=this.nextId++;this.jobs.set(n,{done:t,times:e.times});let{indicatorId:r,config:i,source:a,bars:o}=e;return this.batchFor(o).jobs.push({requestId:n,indicatorId:r,config:i,...a?{source:a}:{}}),n}batchFor(e){if(this.batch?.bars===e)return this.batch;this.sendBatch();let t={bars:e,jobs:[]};return this.batch=t,queueMicrotask(()=>{this.batch===t&&this.sendBatch()}),t}sendBatch(){let e=this.batch;this.batch=null;let t=e?.jobs.filter(e=>this.jobs.has(e.requestId))??[];!e||t.length===0||!this.usable||this.send({message:{type:`calculate`,bars:e.bars,jobs:t},transfer:uo(e.bars)})}cancel(e){let t=new Set(this.batch?.jobs.map(e=>e.requestId)),n=e.filter(e=>this.jobs.delete(e)&&!t.has(e));n.length>0&&this.usable&&this.send({message:{type:`cancel`,requestIds:n},transfer:[]})}terminate(){this.state=`closed`,this.jobs.clear(),this.batch=null,this.outbox=[],this.detach()}attach(e){if(!this.usable){e.terminate();return}this.worker=e,e.addEventListener(`message`,this.onMessage),e.addEventListener(`error`,this.onError),e.addEventListener(`messageerror`,this.onError),this.pingId=this.nextId++,e.postMessage({type:`ping`,requestId:this.pingId});let t=this.outbox;this.outbox=[];for(let n of t)e.postMessage(n.message,n.transfer)}send(e){this.worker?this.worker.postMessage(e.message,e.transfer):this.outbox.push(e)}receive(e){if(!Vu(e))return;if(e.type===`pong`){e.requestId===this.pingId&&this.state===`starting`&&(this.state=`ready`);return}let t=this.jobs.get(e.requestId);if(t){if(e.type===`result`){this.decode(e.requestId,t,e.output);return}this.jobs.delete(e.requestId),t.done(Error(e.message))}}decode(e,t,n){let r=new yo(n,t.times),i=()=>{if(this.jobs.get(e)===t){if(!r.step(5e4)){setTimeout(i,0);return}this.jobs.delete(e),t.done({output:r.output(),...n.state===void 0?{}:{state:wo(n.state)}})}};i()}fail(e){if(!this.usable)return;this.state=`failed`,this.outbox=[],this.detach(),this.batch=null;let t=[...this.jobs.values()];this.jobs.clear();for(let{done:n}of t)n(e)}detach(){let e=this.worker;e&&(this.worker=null,e.removeEventListener(`message`,this.onMessage),e.removeEventListener(`error`,this.onError),e.removeEventListener(`messageerror`,this.onError),e.terminate())}};function Ku(e){return e instanceof Error?e:Error(String(e))}var qu=class{client=null;holders=0;constructor(e=Wu){this.spawn=e}acquire(){let e=this.client??=new Gu(this.spawn);this.holders++;let t=!0;return{client:e,release:()=>{t&&(t=!1,this.holders--,this.holders===0&&this.client===e&&(e.terminate(),this.client=null))}}}},Ju=new qu,W={year:100,quarter:91,month:90,dayOfFive:81,day:80,hour12:73,hour6:72,hour3:71,hour:70,minute30:63,minute15:62,minute5:61,minute:60,within:50},Yu=[...new Set(Object.values(W))].sort((e,t)=>t-e),Xu=256;function Zu(e){return e>=W.year?`year`:e>=W.month?`month`:e>=W.day?`day`:`time`}function Qu(e,t){if(!e)return 0;if(t.year!==e.year)return W.year;if(t.month!==e.month)return t.month%3==1?W.quarter:W.month;if(t.day!==e.day)return t.day%5==0?W.dayOfFive:W.day;if(t.hours!==e.hours){let e=t.hours;return e%12==0?W.hour12:e%6==0?W.hour6:e%3==0?W.hour3:W.hour}if(t.minutes!==e.minutes){let e=t.minutes;return e%30==0?W.minute30:e%15==0?W.minute15:e%5==0?W.minute5:W.minute}return W.within}var $u=256,ed=1.25;function td(e){return e>1?Math.ceil(ed**Math.ceil(Math.log(e)/Math.log(ed)-1e-9)):1}var nd=class{weights=new Uint8Array;times=[];weighed=null;weighedFrom=null;revision=0;chosen=new Int32Array;chosenFor=null;marks(e,t){let n=e.length;if(n===0)return[];let r=td(t.gapBars),i=t.timesPastData?Math.max(n-1,Math.ceil(t.to)):n-1,a=i<=n-1?n:Math.ceil((i+1-n)/$u)*$u+n;this.weigh(e,t.tz,t.exchangeZone??null,a),this.choose(r,a);let o=Math.max(0,Math.floor(t.from)),s=Math.min(i,Math.ceil(t.to)),c=this.chosen,l=0,u=c.length;for(;l<u;){let e=l+u>>1;c[e]<o?l=e+1:u=e}let d=[];for(let e=l;e<c.length&&c[e]<=s;e++){let t=c[e];d.push({index:t,time:this.times[t],weight:this.weights[t]})}return d}weigh(n,r,i,a){let o=n.length,s=(0,t.barTimeUnit)(n),c=(0,t.barsAreDaily)(n)===!0,l=c?e=>(0,t.barDateParts)(e,r,i):e=>(0,t.timeParts)(e,r),u=this.weighed,d=0;if(u&&u.tz===r&&u.exchangeZone===i&&u.daily===c&&u.unit===s){let e=Math.min(u.bars,o),t=this.times;if(n===this.weighedFrom?.deref()&&o>=u.bars)d=e>0&&n[e-1].time*s===t[e-1]?e:0;else{for(;d<e&&n[d].time*s===t[d];)d++;d<e&&(d=0)}}if(this.weighedFrom?.deref()!==n&&(this.weighedFrom=new WeakRef(n)),u&&d===o&&u.bars===o&&u.extent===a)return;let f=d>0&&this.weights.length>=a,p=f?this.weights:new Uint8Array(a+(a>>3)),m=d>0?this.times:[];d>0&&!f&&p.set(this.weights.subarray(0,d)),m.length=d;let h=d>0?l(m[d-1]):null;for(let t=d;t<a;t++){let r=(t<o?n[t].time:e.y(t,n))*s,i=l(r);p[t]=t>0&&r===m[t-1]?0:Qu(h,i),m[t]=r,h=i}this.weights=p,this.times=m,this.weighed={bars:o,tz:r,exchangeZone:i,daily:c,extent:a,unit:s},this.revision++}choose(e,t){let n=this.chosenFor;if(n&&n.gapBars===e&&n.extent===t&&n.revision===this.revision)return;let r=this.weights,i=new Uint8Array(t),a=[],o=new Int32Array(Xu+1);for(let e=0;e<t;e++)o[r[e]+1]++;for(let e=1;e<=Xu;e++)o[e]+=o[e-1];let s=new Int32Array(t),c=o.slice(0,Xu);for(let e=0;e<t;e++)s[c[r[e]]++]=e;for(let n of Yu)for(let r=o[n];r<o[n+1];r++){let n=s[r];if(i[n])continue;a.push(n);let o=Math.max(0,n-e+1),c=Math.min(t-1,n+e-1);for(let e=o;e<=c;e++)i[e]=1}this.chosen=Int32Array.from(a).sort(),this.chosenFor={gapBars:e,extent:t,revision:this.revision}}},rd=e=>e<10?`0`+e:``+e,id=8,ad=new Map;function od(e){let t=ad.get(e);if(!t){let n;try{n=new Intl.DateTimeFormat(e,{month:`short`,timeZone:`UTC`})}catch{n=new Intl.DateTimeFormat(`en-US`,{month:`short`,timeZone:`UTC`})}t=Array.from({length:12},(e,t)=>n.format(Date.UTC(2e3,t,15))),ad.set(e,t)}return t}var sd=class{tz=null;exchangeZone=null;timeFormatter=null;timesPastData=!0;locale=`en-US`;columns=[];marker=new nd;setLocale(e){this.locale=e}setTimezoneOffset(e){this.tz=e}setExchangeTimeZone(e){this.exchangeZone=e}setTimeFormatter(e){this.timeFormatter=e}setTimesPastData(e){this.timesPastData=e}getTimesPastData(){return this.timesPastData}marks(e,t){let n=e.barWidth+e.barSpacing;if(!(n>0)||t.length===0)return[];let r=ai(t),i=this.marker.marks(r,{from:Math.floor(e.offset/n),to:Math.ceil((e.offset+e.chartRect.width)/n),gapBars:80/n,tz:this.tz,timesPastData:this.timesPastData,exchangeZone:this.exchangeZone});return r===t?i:ud(i)}label(e,n,r){if(this.timeFormatter)return this.timeFormatter(e.time,{kind:n,timeZone:this.tz});let i=r?(0,t.barDateParts)(e.time,this.tz,this.exchangeZone):(0,t.timeParts)(e.time,this.tz);if(n===`year`)return String(i.year);if(n===`month`)return od(this.locale)[i.month-1];if(n===`day`)return String(i.day);let a=`${rd(i.hours)}:${rd(i.minutes)}`;return e.weight===W.within?`${a}:${rd(new Date(e.time).getUTCSeconds())}`:a}labelColumns(){return this.columns}render(n,r,i,a,o){let{chartRect:s}=r,c=ai(a),l=o??s.y+s.height;n.strokeStyle=i.style?.axis.time.line??i.axisLine,n.lineWidth=1,n.globalAlpha=.65,n.beginPath(),n.moveTo(s.x,l+.5),n.lineTo(s.x+s.width,l+.5),n.stroke(),n.globalAlpha=1;let u=r.barWidth+r.barSpacing,d=-r.offset+s.x+r.barWidth/2,f=Math.ceil((r.offset+s.width)/u),p=(0,t.barTimeUnit)(c),m=c.length>0?e.y(Math.min(f,c.length-1),c):Date.now(),h=(0,t.tzLabel)(this.tz,m*p),g=`500 ${i.font.sizeSmall-1}px ${i.font.family}`,_=s.x+s.width-4;n.font=g;let v=_-n.measureText(h).width-8,y=`500 ${i.font.sizeSmall}px ${i.font.family}`,b=`600 ${i.font.sizeSmall}px ${i.font.family}`;n.textBaseline=`top`,n.textAlign=`center`,n.fillStyle=i.style?.axis.time.text??i.axisLabel;let x=[],S=this.marks(r,a).sort((e,t)=>t.weight-e.weight||e.index-t.index),C=(0,t.barsAreDaily)(c)===!0;for(let e of S){let t=e.index*u+d;if(t<s.x)continue;let r=Zu(e.weight),i=this.label(e,r,C);n.font=r===`year`?b:y;let a=n.measureText(i).width/2,o=Math.max(t,s.x+a);o+a>v||x.some(e=>o-a<e.right+id&&o+a+id>e.left)||(x.push({left:o-a,right:o+a}),n.fillText(i,o,l+7))}this.columns=x,n.font=g,n.textAlign=`right`,n.textBaseline=`top`,n.globalAlpha=.75,n.fillStyle=i.textSecondary,n.fillText(h,_,l+7),n.globalAlpha=1}},cd={year:3,month:2,day:1,time:0},ld=2;function ud(e){let t=[...new Set(e.map(e=>cd[Zu(e.weight)]))].sort((e,t)=>t-e);if(t.length<=ld)return e;let n=t[ld-1];return e.filter(e=>cd[Zu(e.weight)]>=n)}var dd={line:16,handle:22,alert:16,order:16,button:8,divider:12},fd=300,pd=24,md=class{last=null;tap(e,t=Date.now()){let n=this.last;return n&&t-n.at<=300&&Math.hypot(e.x-n.pos.x,e.y-n.pos.y)<=24?(this.last=null,!0):(this.last={pos:e,at:t},!1)}reset(){this.last=null}},hd=new Set,gd=null,_d=4,vd=8,yd=500,bd=800,xd={ctrl:!1,shift:!1,alt:!1};function Sd(){let e=typeof document<`u`?document.activeElement:null;return e instanceof Element&&e.closest(`[aria-modal="true"], [role="dialog"], [role="menu"]`)!==null}var Cd=class{panHandler=null;zoomHandler=null;crosshairHandler=null;axisDragHandler=null;alertDragHandler=null;axisViewportGetter=null;onAxisDoubleClick=null;onDrawingDoubleClick=null;onDrawingContextMenu=null;zoomArea=!1;idleCss=`crosshair`;showingIdle=!1;onChartContextMenu=null;priceAxisAdd=null;axisStrips=null;savedTouchAction=``;measureHandlers=null;measuring=!1;boxSelectHandlers=null;boxSelecting=!1;onAltClick=null;onEscape=null;onConfirm=null;onClick=null;markerAt=null;onMarkerHover=null;markerClickable=()=>!0;markerPos={x:0,y:0};hoveredMarker=null;downPos=null;downMoved=!1;pressForClick=!1;drawingManager=null;tradingManager=null;paneResizeHandler=null;viewportGetter=null;onOverlayDirty=null;boundHandlers=[];lastTouchDist=0;lastTouchMid={x:0,y:0};touchActive=!1;touchStartPos={x:0,y:0};longPressTimer=null;longPressed=!1;touchFallthrough=!1;touchDecided=!1;touchYielded=!1;taps=new md;pageScroll=!1;touchStartPrevented=!1;lastTouchAt=-1/0;pressPlacedPoint=!1;cachedRect=null;constructor(e){this.element=e}setOverlayDirtyCallback(e){this.onOverlayDirty=e}setPanHandler(e){this.panHandler=e,this.refreshTouchAction()}setZoomHandler(e){this.zoomHandler=e,this.refreshTouchAction()}setCrosshairHandler(e){this.crosshairHandler=e}setIdleCursor(e){this.idleCss=e,this.showingIdle&&(this.element.style.cursor=e)}setAltClickHandler(e){this.onAltClick=e}setEscapeHandler(e){this.onEscape=e}setConfirmHandler(e){this.onConfirm=e}setSignalMarkerHitTest(e,t,n=()=>!0){this.markerAt=e,this.onMarkerHover=t,this.markerClickable=n,e||(this.hoveredMarker=null)}leaveMarker(){this.hoveredMarker!==null&&(this.hoveredMarker=null,this.onMarkerHover?.(null,this.markerPos))}setClickHandler(e){this.onClick=e}setBoxSelectHandlers(e){this.boxSelectHandlers=e}setMeasureHandlers(e){this.measureHandlers=e}setAxisDragHandler(e,t,n){this.axisDragHandler=e,this.axisViewportGetter=t,this.onAxisDoubleClick=n??null}setDrawingManager(e,t){this.drawingManager=e,this.viewportGetter=t}setChartContextMenu(e){this.onChartContextMenu=e}takesPressFromAddButton(e){return e===`move`||e!==null&&!!this.drawingManager?.isEraser()}setPriceAxisAddButton(e,t){this.priceAxisAdd={button:e,onClick:t}}setZoomAreaMode(e){this.zoomArea=e}setDrawingContextMenu(e){this.onDrawingContextMenu=e}setDrawingDoubleClick(e){this.onDrawingDoubleClick=e}setAlertDragHandler(e){this.alertDragHandler=e}setTradingManager(e,t){this.tradingManager=e,this.viewportGetter=t}setAxisStrips(e){this.axisStrips=e}setPaneResizeHandler(e){this.paneResizeHandler=e}setPageScroll(e){this.pageScroll=e,this.refreshTouchAction()}refreshTouchAction(){hd.has(this.element)&&this.element.style.setProperty(`touch-action`,this.touchAction())}pageTakes(){let e=!this.panHandler,t=this.pageScroll||!this.panHandler;return{x:e,y:t,zoom:!this.zoomHandler,any:e||t}}touchAction(){let e=this.pageTakes();if(e.x&&e.y&&e.zoom)return`manipulation`;let t=[e.x&&`pan-x`,e.y&&`pan-y`,e.zoom&&`pinch-zoom`].filter(Boolean);return t.length>0?t.join(` `):`none`}attach(){let e=()=>this.viewportGetter?.()??null;hd.add(this.element),this.savedTouchAction=this.element.style.getPropertyValue(`touch-action`),this.element.style.setProperty(`touch-action`,this.touchAction());let t=e=>{let t=this.axisStrips?.()??null,n=t?.plot??this.axisViewportGetter?.()?.chartRect;if(!n)return null;let r=this.axisDragHandler!==null;if(e.y>(t?.timeAxisTop??n.y+n.height))return r?`time`:null;let i=e.y>=n.y&&e.y<=n.y+n.height;if(e.x>n.x+n.width)return i?r?`price`:null:`inert`;let a=t?.left;return a&&a.width>0&&e.x<n.x&&e.x>=n.x-a.width?i&&a.scales&&r?`price`:`inert`:null},n=e=>{let t=this.axisStrips?.()??null,n=t?.plot??this.axisViewportGetter?.()?.chartRect;if(!n)return`plot`;if(e.y>(t?.timeAxisTop??n.y+n.height))return`timeAxis`;let r=e.y>=n.y&&e.y<=n.y+n.height,i=t?.left,a=!!i&&i.width>0&&e.x<n.x&&e.x>=n.x-i.width;return e.x>n.x+n.width||a?r?`priceAxis`:`pane`:r?`plot`:`pane`},r=e=>{let t=(this.viewportGetter?.()??this.axisViewportGetter?.())?.chartRect;return t?{x:Math.max(t.x,Math.min(t.x+t.width,e.x)),y:Math.max(t.y,Math.min(t.y+t.height,e.y))}:e},i=()=>this.zoomArea?`zoom-in`:this.crosshairHandler&&this.crosshairHandler.getMode()!==`hidden`?this.idleCss:``,a=e=>{this.element.style.cursor!==e&&(this.element.style.cursor=e),this.showingIdle=e!==``&&e===this.idleCss},o=n=>{let r=t(n);if(r===`price`)return`ns-resize`;if(r===`time`)return`ew-resize`;if(r===`inert`)return`default`;let a=this.paneResizeHandler?.cursorAt(n);if(a)return a;if(this.alertDragHandler?.isOverAlert(n))return`ns-resize`;let o=e();if(this.tradingManager?.isOverButton(n))return`pointer`;if(o&&this.tradingManager?.isOverDraggableLine(n,o))return`ns-resize`;if(this.zoomArea)return`zoom-in`;let s=o?this.drawingManager?.hoverCursorAt(n,o):null;return this.takesPressFromAddButton(s??null)?s??i():o&&this.priceAxisAdd?.button.hit(n,o)?(this.drawingManager?.clearHover(),`pointer`):s||i()},s=!1,c=``,l=e=>{if(!(e.buttons&1)){b(e);return}g(e)},u=()=>{s||(s=!0,this.leaveMarker(),c=document.documentElement.style.userSelect,document.documentElement.style.userSelect=`none`,document.addEventListener(`mousemove`,l))},d=()=>{s&&(s=!1,document.documentElement.style.userSelect=c,document.removeEventListener(`mousemove`,l))},f=e=>e===this.element||e instanceof HTMLCanvasElement,p=(n,r,o)=>{this.panHandler?.cancelMomentum();let s=e(),c=o===`mouse`,l=c?void 0:dd;this.pressPlacedPoint=!1,c||this.drawingManager?.setModifiers({ctrl:!1,shift:!1}),this.downPos=n,this.downMoved=!1,this.pressForClick=!1;let u=t(n);if(u===`inert`)return`inert`;if(u&&this.axisDragHandler)return this.axisDragHandler.begin(u,n),`taken`;if(this.paneResizeHandler?.tryBegin(n,l?.divider))return`taken`;let d=!!this.drawingManager?.getActiveTool()||!!this.tradingManager?.isBracketActive()||!!this.tradingManager?.isOrderDraftActive();return r.ctrl&&!d&&!this.zoomArea&&s&&this.drawingManager?.beginCopyDrag(n,s,l)?(c&&a(`copy`),`taken`):this.boxSelectHandlers&&(this.zoomArea||r.ctrl&&!d)?(this.boxSelecting=!0,this.boxSelectHandlers.begin(n),c&&a(i()),this.onOverlayDirty?.(!0),`taken`):r.shift&&this.measureHandlers&&!d&&!(s&&this.drawingManager?.hoverCursorAt(n,s))?(this.measuring=!0,this.measureHandlers.begin(n),this.onOverlayDirty?.(!0),`taken`):r.alt&&this.onAltClick?(this.onAltClick(n),`taken`):this.priceAxisAdd&&s&&!d&&this.priceAxisAdd.button.hit(n,s)&&!this.alertDragHandler?.isOverAlert(n)&&!this.tradingManager?.isOverButton(n)&&!this.tradingManager?.isOverDraggableLine(n,s)&&!this.takesPressFromAddButton(this.drawingManager?.hoverCursorAt(n,s)??null)?(this.drawingManager?.clearHover(),this.priceAxisAdd.onClick(n),`menu`):this.tradingManager&&s&&this.tradingManager.onPointerDown(n,s,l)?(c&&a(this.tradingManager.isOverButton(n)?`pointer`:`ns-resize`),`taken`):this.drawingManager&&s&&this.drawingManager.onPointerDown(n,s,l)?(c&&this.drawingManager.isDragging()&&a(`grabbing`),this.pressPlacedPoint=!!this.drawingManager.getActiveTool(),d||this.drawingManager.isEraser()?`taken`:`drawing`):this.alertDragHandler?.tryBegin(n,l?.alert)?(this.onOverlayDirty?.(),`taken`):(this.pressForClick=!0,this.panHandler&&(this.panHandler.onPointerDown(n),c&&a(`grabbing`)),`pan`)},m=e=>{if(gd=this.element,e.button!==0||!f(e.target))return;u(),this.invalidateRect();let t={ctrl:e.ctrlKey||e.metaKey,shift:e.shiftKey,alt:e.altKey};this.drawingManager?.setModifiers({ctrl:t.ctrl,shift:t.shift}),p(this.getMousePos(e),t,`mouse`)===`menu`&&e.preventDefault()},h=e=>{if(!s){if(!f(e.target)){this.leaveMarker();return}g(e)}},g=e=>{let t=this.getMousePos(e);if(this.drawingManager?.setModifiers({ctrl:e.ctrlKey||e.metaKey,shift:e.shiftKey}),!s){let e=this.markerAt?.(t)??null;e!==this.hoveredMarker&&(this.hoveredMarker=e,this.onMarkerHover?.(e,t)),e&&(this.markerPos=t),a(e&&this.markerClickable()?`pointer`:o(t))}_(t,`mouse`,s)},_=(t,n,i,a=t)=>{let o=e();if(this.downPos&&!this.downMoved){let e=n===`mouse`?_d:vd;Math.hypot(t.x-this.downPos.x,t.y-this.downPos.y)>e&&(this.downMoved=!0)}if(this.axisDragHandler?.isActive()){this.axisDragHandler.move(t),n===`touch`&&this.onOverlayDirty?.();return}if(this.paneResizeHandler?.isActive()){this.paneResizeHandler.move(t),n===`touch`&&this.onOverlayDirty?.();return}if(this.alertDragHandler?.isActive()){this.alertDragHandler.move(r(t)),this.onOverlayDirty?.();return}if(this.measuring&&this.measureHandlers){this.measureHandlers.move(t),this.onOverlayDirty?.(!0);return}if(this.boxSelecting&&this.boxSelectHandlers){this.boxSelectHandlers.move(t),this.onOverlayDirty?.(!0);return}if(this.tradingManager&&o&&this.tradingManager.onPointerMove(i?r(t):t,o)){this.crosshairHandler?.onPointerMove(t),this.onOverlayDirty?.();return}if(this.drawingManager&&o&&this.drawingManager.onPointerMove(t,o)){this.crosshairHandler?.onPointerMove(t),this.onOverlayDirty?.();return}this.panHandler?.onPointerMove(a),this.crosshairHandler?.onPointerMove(t),this.onOverlayDirty?.(!i)},v=(t,n,r=!1)=>{let i=this.downPos,a=this.downMoved&&i!==null,o=this.pressPlacedPoint,s=this.pressForClick&&!this.downMoved&&i!==null&&!r;if(this.pressForClick=!1,this.pressPlacedPoint=!1,this.downPos=null,this.downMoved=!1,this.boxSelecting&&this.boxSelectHandlers)return this.boxSelecting=!1,r?this.boxSelectHandlers.cancel():this.boxSelectHandlers.end(),this.onOverlayDirty?.(!0),!1;if(this.axisDragHandler?.isActive())return this.axisDragHandler.end(),!1;if(this.paneResizeHandler?.isActive())return this.paneResizeHandler.end(),!1;if(this.alertDragHandler?.isActive())return this.alertDragHandler.end(),this.onOverlayDirty?.(),!1;if(this.measuring&&this.measureHandlers)return this.measuring=!1,this.measureHandlers.end(),this.onOverlayDirty?.(!0),!1;if(r?this.tradingManager?.cancelPointer():this.tradingManager?.onPointerUp(t??void 0))return!1;let c=e();return r&&o&&this.drawingManager?.takeBackPoint(),n===`touch`&&a&&!r&&t&&c&&this.drawingManager?.placeAt(t,c),this.drawingManager?.onPointerUp()?!1:(this.panHandler?.onPointerUp(),r&&this.panHandler?.cancelMomentum(),s&&this.onClick&&this.onClick(i),s)},y=(n,r)=>{let i=t(n);if(i){i!==`inert`&&this.onAxisDoubleClick?.(i);return}let a=e();if(!a||this.drawingManager?.justFinished())return;let o=this.drawingManager?.drawingAt(n,a,r);o&&this.onDrawingDoubleClick?.(o)},b=e=>{if(e.button!==0&&e.type===`mouseup`||!s)return;d();let t=this.getMousePos(e);a(o(t)),v(t,`mouse`)},x=e=>{y(this.getMousePos(e))},S=()=>{if(this.leaveMarker(),s){this.crosshairHandler?.onPointerLeave(),this.onOverlayDirty?.(!0);return}a(``),this.panHandler?.onPointerUp(),this.drawingManager?.onPointerUp(),this.drawingManager?.clearHover(),this.tradingManager?.onPointerUp(),this.alertDragHandler?.end(),this.paneResizeHandler?.end(),this.crosshairHandler?.onPointerLeave(),this.pressForClick=!1,this.downPos=null,this.onOverlayDirty?.()},C=e=>{if(!this.zoomHandler||this.pageScroll&&!e.ctrlKey)return;e.preventDefault();let t=this.getMousePos(e);this.zoomHandler.onWheel(e.deltaY,t)},w=e=>{(e.key===`Shift`||e.key===`Control`||e.key===`Meta`)&&this.drawingManager?.setModifiers({ctrl:e.ctrlKey||e.metaKey,shift:e.shiftKey})},T=()=>this.drawingManager?.setModifiers({ctrl:!1,shift:!1}),E=e=>{if(w(e),Sd())return;if(e.key===`Escape`&&this.boxSelecting&&this.boxSelectHandlers&&(this.boxSelecting=!1,this.boxSelectHandlers.cancel(),this.onOverlayDirty?.(!0)),e.key===`Escape`&&this.onEscape&&this.onEscape(),e.key===`Enter`&&this.onConfirm&&this.onConfirm()){e.preventDefault();return}if(e.key!==`Escape`&&!this.ownsShortcuts())return;let t=this.drawingManager?.isDragging()??!1;this.drawingManager?.onKeyDown(e.key,e.ctrlKey||e.metaKey,e.shiftKey)&&(e.preventDefault(),t&&e.key===`Escape`&&a(i()))},D=t=>{if(this.touchActive||Date.now()-this.lastTouchAt<bd){t.preventDefault();return}let r=e();if(!r)return;let i=this.getMousePos(t),a=this.onDrawingContextMenu&&!this.drawingManager?.getActiveTool()?this.drawingManager?.drawingAt(i,r):null;if(a){t.preventDefault(),this.onDrawingContextMenu?.(a,i);return}if(this.tradingManager?.onContextMenu(i,r)){t.preventDefault();return}this.onChartContextMenu?.(n(i),i)&&t.preventDefault()},O=e=>{if(gd=this.element,!(!this.touchActive&&!f(e.target))){if(this.lastTouchAt=Date.now(),this.invalidateRect(),e.touches.length===1){let t=this.getTouchPos(e.touches[0]);this.touchStartPos=t,this.longPressed=!1,this.touchYielded=!1,this.touchDecided=!1;let n=p(t,xd,`touch`);if(this.touchActive=!0,this.touchFallthrough=n===`pan`||n===`inert`,this.touchStartPrevented=!(this.touchFallthrough&&this.pageTakes().any),this.touchStartPrevented&&e.preventDefault(),n===`drawing`){k(t);return}if(n!==`pan`)return;this.onAltClick&&(this.clearLongPress(),this.longPressTimer=setTimeout(()=>{this.longPressTimer=null,this.longPressed=!0,this.pressForClick=!1,this.onAltClick?.(t),this.panHandler?.onPointerUp(),this.panHandler?.cancelMomentum(),this.onOverlayDirty?.(!0)},yd)),this.crosshairHandler?.onPointerMove(t),this.onOverlayDirty?.(!0)}else if(e.touches.length===2){if(this.clearLongPress(),this.touchActive&&!this.touchYielded&&this.lastTouchDist===0&&v(null,`touch`,!0),!this.zoomHandler&&!this.panHandler){this.touchActive=!1;return}e.cancelable&&e.preventDefault(),this.lastTouchDist=this.getTouchDistance(e.touches[0],e.touches[1]),this.lastTouchMid=this.getTouchMidpoint(e.touches[0],e.touches[1]),this.touchActive=!0,this.touchYielded=!1}}},k=t=>{this.onDrawingContextMenu&&(this.clearLongPress(),this.longPressTimer=setTimeout(()=>{this.longPressTimer=null;let n=e(),r=n?this.drawingManager?.drawingAt(t,n,dd.line):null;r&&(v(null,`touch`,!0),this.longPressed=!0,this.touchYielded=!0,this.crosshairHandler?.onPointerLeave(),this.onDrawingContextMenu?.(r,t),this.onOverlayDirty?.())},yd))},A=e=>{if(this.touchDecided)return!1;let t=e.x-this.touchStartPos.x,n=e.y-this.touchStartPos.y;if(Math.hypot(t,n)<=vd)return!1;this.touchDecided=!0;let r=this.pageTakes();return Math.abs(n)>=Math.abs(t)?r.y:r.x},j=e=>{if(!(!this.touchActive||this.touchYielded)){if(e.touches.length===1){let t=this.getTouchPos(e.touches[0]);if(this.lastTouchDist>0){e.cancelable&&e.preventDefault(),this.panHandler?.onPointerMove(this.pageScroll?{x:t.x,y:this.touchStartPos.y}:t),this.onOverlayDirty?.();return}if(this.longPressTimer&&Math.hypot(t.x-this.touchStartPos.x,t.y-this.touchStartPos.y)>vd&&this.clearLongPress(),this.touchFallthrough&&this.pageTakes().any){if(!this.touchDecided&&Math.hypot(t.x-this.touchStartPos.x,t.y-this.touchStartPos.y)<=vd)return;if(A(t)){this.touchYielded=!0,v(null,`touch`,!0),this.crosshairHandler?.onPointerLeave(),this.onOverlayDirty?.(!0);return}}e.cancelable&&e.preventDefault(),_(t,`touch`,!0,this.pageScroll?{x:t.x,y:this.touchStartPos.y}:t)}else if(e.touches.length===2){e.cancelable&&e.preventDefault();let t=this.getTouchDistance(e.touches[0],e.touches[1]),n=this.getTouchMidpoint(e.touches[0],e.touches[1]);this.lastTouchDist>0&&t>0&&this.zoomHandler?.onPinch(t/this.lastTouchDist,n);let r=this.lastTouchMid.x-n.x;Math.abs(r)>1&&(this.panHandler?.onPointerDown(this.lastTouchMid),this.panHandler?.onPointerMove({x:n.x,y:this.lastTouchMid.y})),this.lastTouchDist=t,this.lastTouchMid=n,this.onOverlayDirty?.()}}},ee=e=>{if(this.clearLongPress(),this.touchActive)if(this.lastTouchAt=Date.now(),e.touches.length===0){let t=e.changedTouches?.[0],n=t?this.getTouchPos(t):null,r=this.lastTouchDist>0,i=!r&&!this.longPressed&&!this.touchYielded&&this.downPos!==null&&!this.downMoved;this.touchYielded||(r?this.panHandler?.onPointerUp():v(n,`touch`),!this.touchStartPrevented&&e.cancelable&&e.preventDefault()),i&&n&&this.taps.tap(n)?y(n,dd.line):i||this.taps.reset(),this.crosshairHandler?.onPointerLeave(),this.touchActive=!1,this.touchYielded=!1,this.lastTouchDist=0,this.onOverlayDirty?.()}else if(e.touches.length===1&&!this.touchYielded){let t=this.getTouchPos(e.touches[0]);this.touchStartPos=t,this.panHandler?.onPointerDown(t)}else e.touches.length===2&&this.lastTouchDist>0&&(this.lastTouchDist=this.getTouchDistance(e.touches[0],e.touches[1]),this.lastTouchMid=this.getTouchMidpoint(e.touches[0],e.touches[1]))},te=()=>{this.clearLongPress(),this.touchActive&&(this.lastTouchAt=Date.now(),this.touchYielded||(this.lastTouchDist>0?(this.panHandler?.onPointerUp(),this.panHandler?.cancelMomentum()):v(null,`touch`,!0)),this.taps.reset(),this.crosshairHandler?.onPointerLeave(),this.touchActive=!1,this.touchYielded=!1,this.lastTouchDist=0,this.onOverlayDirty?.())},ne=()=>this.invalidateRect(),re=()=>this.invalidateRect(),ie=()=>this.invalidateRect(),ae=e=>{let t=e.target instanceof Node&&this.element.contains(e.target)&&f(e.target);(s||t)&&e.preventDefault()};this.element.addEventListener(`mousedown`,m),this.element.addEventListener(`mousemove`,h),document.addEventListener(`dragstart`,ae,!0),document.addEventListener(`mouseup`,b),this.element.addEventListener(`mouseleave`,S),this.element.addEventListener(`dblclick`,x),this.element.addEventListener(`wheel`,C,{passive:!1}),this.element.addEventListener(`contextmenu`,D),this.element.addEventListener(`touchstart`,O,{passive:!1}),this.element.addEventListener(`touchmove`,j,{passive:!1}),this.element.addEventListener(`touchend`,ee),this.element.addEventListener(`touchcancel`,te),document.addEventListener(`keydown`,E),document.addEventListener(`keyup`,w),window.addEventListener(`blur`,T),window.addEventListener(`resize`,ne),document.addEventListener(`scroll`,re,{capture:!0,passive:!0}),this.element.addEventListener(`mouseenter`,ie),this.boundHandlers.push(d,()=>this.element.removeEventListener(`mousedown`,m),()=>document.removeEventListener(`keyup`,w),()=>window.removeEventListener(`blur`,T),()=>document.removeEventListener(`dragstart`,ae,!0),()=>this.element.removeEventListener(`mousemove`,h),()=>document.removeEventListener(`mouseup`,b),()=>this.element.removeEventListener(`mouseleave`,S),()=>this.element.removeEventListener(`dblclick`,x),()=>this.element.removeEventListener(`wheel`,C),()=>this.element.removeEventListener(`contextmenu`,D),()=>this.element.removeEventListener(`touchstart`,O),()=>this.element.removeEventListener(`touchmove`,j),()=>this.element.removeEventListener(`touchend`,ee),()=>this.element.removeEventListener(`touchcancel`,te),()=>document.removeEventListener(`keydown`,E),()=>window.removeEventListener(`resize`,ne),()=>document.removeEventListener(`scroll`,re,{capture:!0}),()=>this.element.removeEventListener(`mouseenter`,ie))}detach(){hd.delete(this.element),this.savedTouchAction?this.element.style.setProperty(`touch-action`,this.savedTouchAction):this.element.style.removeProperty(`touch-action`),gd===this.element&&(gd=null);for(let e of this.boundHandlers)e();this.boundHandlers=[],this.cachedRect=null,this.clearLongPress()}clearLongPress(){this.longPressTimer&&=(clearTimeout(this.longPressTimer),null)}invalidateRect(){this.cachedRect=null}getRect(){return this.cachedRect||=this.element.getBoundingClientRect(),this.cachedRect}ownsShortcuts(){let e=document.activeElement;if(e&&(e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.tagName===`SELECT`||e.isContentEditable))return!1;for(let t of hd)if(e&&t.contains(e))return t===this.element;return gd===null||gd===this.element}getMousePos(e){let t=this.getRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}getTouchPos(e){let t=this.getRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}getTouchDistance(e,t){return Math.hypot(t.clientX-e.clientX,t.clientY-e.clientY)}getTouchMidpoint(e,t){let n=this.getRect();return{x:(e.clientX+t.clientX)/2-n.left,y:(e.clientY+t.clientY)/2-n.top}}},wd=16,Td=3,Ed=wd+Td,Dd=class{enabled=!1;setEnabled(e){this.enabled=e}isEnabled(){return this.enabled}hit(e,t){if(!this.enabled)return!1;let{x:n,y:r,width:i,height:a}=t.chartRect,o=n+i-wd-Td;return e.x>=o&&e.x<=n+i&&e.y>=r&&e.y<=r+a}render(e,t,n,r){if(!this.enabled||!r)return;let{x:i,y:a,width:o,height:s}=t.chartRect;if(r.y<a||r.y>a+s||r.x<i||r.x>i+o)return;let c=i+o-Td-wd/2,l=wd/2;e.fillStyle=n.background,e.strokeStyle=n.axisLabelBackground,e.lineWidth=1,e.beginPath(),e.arc(c,r.y,l-.5,0,Math.PI*2),e.fill(),e.stroke(),e.strokeStyle=n.text,e.lineWidth=1.5,e.beginPath(),e.moveTo(c-l*.45,r.y),e.lineTo(c+l*.45,r.y),e.moveTo(c,r.y-l*.45),e.lineTo(c,r.y+l*.45),e.stroke()}},Od=100,kd=50,Ad=.1,jd=60,Md=16;function Nd(){return typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches}var Pd=class{dragging=!1;lastX=0;lastY=0;samples=[];momentumId=0;callback;onStart;friction=.92;constructor(e,t){this.callback=e,this.onStart=t}isDragging(){return this.dragging}onPointerDown(e){this.dragging=!0,this.lastX=e.x,this.lastY=e.y,this.samples=[{t:Date.now(),x:e.x,y:e.y}],this.stopMomentum(),this.onStart?.()}onPointerMove(e){if(!this.dragging)return;let t=this.lastX-e.x,n=this.lastY-e.y;this.lastX=e.x,this.lastY=e.y;let r=Date.now();for(this.samples.push({t:r,x:e.x,y:e.y});this.samples.length>2&&r-this.samples[1].t>Od;)this.samples.shift();(t||n)&&this.callback(t,n)}onPointerUp(){if(!this.dragging)return;this.dragging=!1;let e=this.releaseVelocity(Date.now());this.samples=[],!Nd()&&e&&Math.hypot(e.x,e.y)>Ad&&this.startMomentum(e.x,e.y)}cancelMomentum(){this.stopMomentum()}releaseVelocity(e){let t=this.samples[this.samples.length-1];if(!t||e-t.t>kd)return null;let n=this.samples.find(e=>t.t-e.t<=Od)??this.samples[0],r=t.t-n.t;return r<=0?null:{x:(n.x-t.x)/r,y:(n.y-t.y)/r}}startMomentum(e,t){this.stopMomentum();let n=e*Md,r=t*Md,i=Math.hypot(n,r);i>jd&&(n*=jd/i,r*=jd/i);let a=null,o=e=>{let t=a===null?1:Math.min(4,Math.max(0,(e-a)/Md));a=e;let i=this.friction**t;if(n*=i,r*=i,Math.hypot(n,r)<.5){this.momentumId=0;return}this.callback(n*t,r*t),this.momentumId=requestAnimationFrame(o)};this.momentumId=requestAnimationFrame(o)}stopMomentum(){this.momentumId&&=(cancelAnimationFrame(this.momentumId),0)}},Fd=class{callback;sensitivity;pendingDelta=0;pendingScale=1;pendingCenterX=0;rafId=0;constructor(e,t=.001){this.callback=e,this.sensitivity=t}onWheel(e,t){this.pendingDelta+=-e*this.sensitivity,this.pendingCenterX=t.x,this.schedule()}onPinch(e,t){!(e>0)||!Number.isFinite(e)||(this.pendingScale*=e,this.pendingCenterX=t.x,this.schedule())}schedule(){this.rafId||=requestAnimationFrame(()=>{this.rafId=0;let e=(1+this.pendingDelta)*this.pendingScale-1,t=this.pendingCenterX;this.pendingDelta=0,this.pendingScale=1,this.callback(e,t)})}dispose(){this.rafId&&=(cancelAnimationFrame(this.rafId),0)}},Id=class{dragging=!1;axis=null;startPos={x:0,y:0};lastPos={x:0,y:0};moved=!1;threshold=3;sensitivity=.005;constructor(e,t){this.onPriceScale=e,this.onTimeScale=t}begin(e,t){this.dragging=!0,this.axis=e,this.startPos=t,this.lastPos=t,this.moved=!1}move(e){if(!this.dragging||!this.axis)return!1;let t=e.x-this.startPos.x,n=e.y-this.startPos.y;if(!this.moved&&Math.hypot(t,n)<this.threshold)return!1;if(this.moved=!0,this.axis===`price`){let t=e.y-this.lastPos.y,n=Math.exp(t*this.sensitivity);this.onPriceScale(n)}else{let t=e.x-this.lastPos.x,n=Math.exp(t*this.sensitivity);this.onTimeScale(n)}return this.lastPos=e,!0}end(){let e=this.dragging&&this.moved;return this.dragging=!1,this.axis=null,this.moved=!1,e}isActive(){return this.dragging}},Ld=class{draggingId=null;constructor(e,t){this.alerts=e,this.viewportGetter=t}isOverAlert(e){let t=this.viewportGetter();return t?this.alerts.getAlertAtPoint(e,t)!==null:!1}tryBegin(e,t){let n=this.viewportGetter();if(!n)return!1;let r=this.alerts.getAlertAtPoint(e,n,t);return r?(this.draggingId=r.id,!0):!1}move(t){if(this.draggingId===null)return;let n=this.viewportGetter();n&&this.alerts.updateAlertPrice(this.draggingId,e.M(t.y,n))}end(){this.draggingId=null}isActive(){return this.draggingId!==null}},Rd=class{state=null;layoutGetter=null;onResize=null;constructor(e=4){this.tolerance=e}configure(e,t){this.layoutGetter=e,this.onResize=t}hitTest(e,t,n=this.tolerance){for(let r of t.dividers)if(zd(e,r.rect,n)){let e=t.panels.find(e=>e.config.id===r.panelId);if(e)return{panelId:r.panelId,orientation:r.orientation,position:e.config.position,size:r.orientation===`horizontal`?e.rect.height:e.rect.width}}return null}cursorAt(e){let t=this.layoutGetter?.();if(!t)return null;let n=this.hitTest(e,t);return n?n.orientation===`horizontal`?`ns-resize`:`ew-resize`:null}tryBegin(e,t){let n=this.layoutGetter?.();if(!n)return!1;let r=this.hitTest(e,n,Math.max(t??0,this.tolerance));return r?(this.state={panelId:r.panelId,position:r.position,startSize:r.size,startPos:e},!0):!1}move(e){let t=this.computeSize(e);t&&this.onResize?.(t.panelId,t.size)}computeSize(e){let t=this.state;if(!t)return null;let n=0;switch(t.position){case`bottom`:n=t.startPos.y-e.y;break;case`top`:n=e.y-t.startPos.y;break;case`left`:n=e.x-t.startPos.x;break;case`right`:n=t.startPos.x-e.x;break}return{panelId:t.panelId,size:t.startSize+n}}end(){this.state=null}isActive(){return this.state!==null}};function zd(e,t,n){return e.x>=t.x-n&&e.x<=t.x+t.width+n&&e.y>=t.y-n&&e.y<=t.y+t.height+n}var Bd=10,Vd=6,Hd=16,Ud=18,Wd=8,Gd=16,Kd=15,qd={min:0,max:1,step:.2,ticks:[0,.2,.4,.6,.8,1]};function Jd(e){for(let t=0;t<=Kd;t++){let n=e*10**t,r=Math.round(n);if(r!==0&&Math.abs(r-n)<1e-9*Math.abs(n))return t}return Kd}var Yd=(e,t)=>{let n=Number(e.toFixed(t));return n===0?0:n};function Xd(e,t,n=5){let r=Math.min(e,t),i=Math.max(e,t);if((!Number.isFinite(r)||!Number.isFinite(i))&&(r=0,i=1),r===i){let e=Math.abs(r)||1;r-=e/2,i+=e/2}let a=(i/2-r/2)/Math.max(1,n)*2;if(!Number.isFinite(a)||a<=0)return qd;let o=10**Math.floor(Math.log10(a)),s=a/o,c=(s<=1?1:s<=2?2:s<=2.5?2.5:s<=5?5:10)*o;if(!Number.isFinite(c)||c<=0)return qd;let l=Jd(c),u=Math.floor(r/c+1e-9),d=Math.ceil(i/c-1e-9),f=[];for(let e=u;e<=d;e++)f.push(Yd(e*c,l));return f.length<2||!f.every(Number.isFinite)?qd:{min:f[0],max:f[f.length-1],step:Yd(c,l),ticks:f}}function G(e,t,n,r,i=!1){let a=e.max===e.min?.5:(t-e.min)/(e.max-e.min);return i?n+r*(1-a):n+r*a}var Zd=new Intl.NumberFormat(void 0,{maximumFractionDigits:2}),Qd=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1});function $d(e){return Math.abs(e)>=1e4?Qd.format(e):Zd.format(e)}function K(e){let t=Jd(e.step),n=new Intl.NumberFormat(void 0,{minimumFractionDigits:t,maximumFractionDigits:t});if(Math.max(Math.abs(e.min),Math.abs(e.max))>=1e4&&e.step%1e3==0){let t=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:2}),n=e.ticks.map(e=>t.format(e));if(new Set(n).size===n.length)return e=>t.format(e)}return e=>n.format(e)}function ef(e,n){return n??t.TC_SERIES_COLORS[e%t.TC_SERIES_COLORS.length]}function q(e,t,n=``){return`${n?`${n} `:``}${t}px ${e.font.family}`}function tf(e,t){return(n,r=11)=>(e.font=q(t,r),e.measureText(n).width)}function nf(e,t,n,r=!1){let i=[],a=0,o=0;for(let s of e){let e=Bd+Vd+n(s.label,11);a>0&&(r||a+e>t)&&(o++,a=0),i.push({...s,x:a,y:o*Ud}),a+=e+Hd}let s=e.length===0?0:o+1;return{items:i,rows:s,height:s*Ud}}function rf(e,t,n,r,i){e.save(),e.font=q(i,11),e.textBaseline=`middle`,e.textAlign=`left`;for(let a of t.items){let t=r+a.y+Ud/2;e.fillStyle=a.color,e.fillRect(n+a.x,t-Bd/2,Bd,Bd),e.fillStyle=i.textSecondary,e.fillText(a.label,n+a.x+Bd+Vd,t)}e.restore()}function af(e,n,r,i,a){if(n.length===0)return;e.save();let o=n.some(e=>e.color)?Bd+Vd:0,s=0;for(let t of n)e.font=q(a,11,t.bold?`600`:``),s=Math.max(s,e.measureText(t.text).width);let c=s+o+Wd*2,l=n.length*Gd+Wd*2-4,u=r.x+14,d=r.y+14;u+c>i.x+i.width&&(u=r.x-14-c),d+l>i.y+i.height&&(d=r.y-14-l),u=Math.max(i.x,u),d=Math.max(i.y,d),e.fillStyle=(0,t.withAlpha)(a.axisLabelBackground,.94),e.strokeStyle=a.grid,e.lineWidth=1,e.beginPath(),typeof e.roundRect==`function`?e.roundRect(u,d,c,l,6):e.rect(u,d,c,l),e.fill(),e.stroke(),e.textBaseline=`middle`,e.textAlign=`left`,n.forEach((t,n)=>{let r=d+Wd+n*Gd+Gd/2-2;t.color&&(e.fillStyle=t.color,e.fillRect(u+Wd,r-4,8,8)),e.font=q(a,11,t.bold?`600`:``),e.fillStyle=t.bold?a.text:a.textSecondary,e.fillText(t.text,u+Wd+o,r)}),e.restore()}function of(e,t,n,r,i,a){e.save(),e.font=q(i,11),e.fillStyle=i.axisLabel,e.strokeStyle=i.grid,e.lineWidth=1;for(let i of n.ticks)if(r===`vertical`){let r=Math.round(G(n,i,t.y,t.height,!0))+.5;e.beginPath(),e.moveTo(t.x,r),e.lineTo(t.x+t.width,r),e.stroke(),e.textAlign=`right`,e.textBaseline=`middle`,e.fillText(a(i),t.x-6,r)}else{let r=Math.round(G(n,i,t.x,t.width))+.5;e.beginPath(),e.moveTo(r,t.y),e.lineTo(r,t.y+t.height),e.stroke(),e.textAlign=`center`,e.textBaseline=`top`,e.fillText(a(i),r,t.y+t.height+6)}e.restore()}function sf(e,t,n,r=11){if(n(e,r)<=t)return e;let i=e;for(;i.length>1&&n(`${i}…`,r)>t;)i=i.slice(0,-1);return i.length>1?`${i}…`:``}var cf=8,lf=32,uf=new Map;function df(e){let t=uf.get(e);return t===void 0&&(t=ff(e),uf.size>512&&uf.clear(),uf.set(e,t)),t}function ff(e){let t=e.trim(),n=t.match(/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i);if(n){let e=n[1];return e.length<=4&&(e=[...e.slice(0,3)].map(e=>e+e).join(``)),[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}let r=t.match(/^rgba?\(\s*(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)/i);return r?[Number(r[1]),Number(r[2]),Number(r[3])]:null}function pf(e,t,n){let r=df(e),i=df(t);if(!r||!i)return n<.5?e:t;let a=e=>Math.round(r[e]+(i[e]-r[e])*n);return`rgb(${a(0)},${a(1)},${a(2)})`}function mf(e,t,n){let r=1/0,i=-1/0;for(let t of e)Number.isFinite(t)&&(t<r&&(r=t),t>i&&(i=t));let a=0,o=1;if(r<=i){let e=Math.max(Math.abs(r),Math.abs(i))||1;a=r<0?-e:0,o=r<0?e:i||1}return{negative:n?.negative??t.candleDown,zero:n?.zero??pf(t.background,t.text,.14),positive:n?.positive??t.candleUp,min:n?.min!==void 0&&Number.isFinite(n.min)?n.min:a,max:n?.max!==void 0&&Number.isFinite(n.max)?n.max:o}}function hf(e,t){return!Number.isFinite(e)||e===0?pf(t.zero,t.zero,0):e<0?pf(t.zero,t.negative,t.min<0?Math.min(1,e/t.min):1):pf(t.zero,t.positive,t.max>0?Math.min(1,e/t.max):1)}var gf=`#11151b`,_f=.0076;function vf(e){let t=df(e);if(!t)return`#ffffff`;let[n,r,i]=t.map(e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}),a=.2126*n+.7152*r+.0722*i;return(a+.05)/(_f+.05)>1.05/(a+.05)?gf:`#ffffff`}function yf(e,t,n,r,i){let a=Math.min(180,t.width);if(a<40||!(n.max>n.min))return;let{x:o,y:s}=t,c=n.max-n.min;e.save();for(let t=0;t<lf;t++){let r=(t+.5)/lf;e.fillStyle=hf(n.min+c*r,n),e.fillRect(o+a*t/lf,s,a/lf+.5,cf)}e.font=q(i,10),e.fillStyle=i.textSecondary,e.textBaseline=`top`;let l=s+cf+4;e.textAlign=`left`,e.fillText(r(n.min),o,l),e.textAlign=`right`,e.fillText(r(n.max),o+a,l);let u=o+a*-n.min/c;n.min<0&&n.max>0&&u-o>28&&o+a-u>28&&(e.textAlign=`center`,e.fillText(r(0),u,l)),e.restore()}var bf=.2,xf=class{position=null;callback=null;data=[];source=null;tz=null;exchangeZone=null;timeFormatter=null;timesPastData=!0;setTimesPastData(e){this.timesPastData=e}getTimesPastData(){return this.timesPastData}setTimeFormatter(e){this.timeFormatter=e}setTimezoneOffset(e){this.tz=e}setExchangeTimeZone(e){this.exchangeZone=e}magnetMode=!0;mode=`magnet`;cursor=`cross`;spanTints=[];pricePrecision=null;locale=`en-US`;syncedSlot=null;pendingBarIndex=null;pendingPoint=null;callbackScheduled=!1;lastCallbackBarIndex=-1;reportTop=null;reportBottom=null;setCallback(e){this.callback=e}setData(e){this.data=e}setDataSource(e){this.source=e}series(){return this.source?.()??this.data}setMagnetMode(e){this.magnetMode=e,this.mode=e?`magnet`:`normal`}setMode(e){this.mode=e,this.magnetMode=e===`magnet`}getMode(){return this.mode}setCursor(e){this.cursor=e}getCursor(){return this.cursor}drawsLines(){return this.mode!==`hidden`&&this.cursor!==`arrow`}setPricePrecision(e){this.pricePrecision=e}setLocale(e){this.locale=e}getPosition(){return this.position}setSyncedSlot(e){this.syncedSlot=e!==null&&Number.isFinite(e)?e:null}getSyncedSlot(){return this.syncedSlot}setReportBounds(e){this.reportTop=e?.top??null,this.reportBottom=e?.bottom??null}onPointerMove(e){this.position=e}getReportedBarIndex(){return this.lastCallbackBarIndex>=0?this.lastCallbackBarIndex:null}refresh(){this.lastCallbackBarIndex<0||!this.pendingPoint||(this.pendingBarIndex=this.lastCallbackBarIndex,this.scheduleCallback())}onPointerLeave(){this.position=null,this.pendingBarIndex=null,this.pendingPoint=null,this.lastCallbackBarIndex=-1,this.flushCallback(null,null)}render(n,r,i){if(this.mode===`hidden`)return;let a=this.cursor!==`arrow`;if(!this.position){this.syncedSlot!==null&&a&&this.renderSynced(n,r,i,this.syncedSlot);return}let{chartRect:o}=r,{x:s,y:c}=this.position;if(s<o.x||s>o.x+o.width)return;let l=o.y+o.height;if(c<Math.min(this.reportTop??o.y,o.y)||c>Math.max(this.reportBottom??l,l))return;let u=c>=o.y&&c<=l,d=e.A(s,r),f=this.series().length,p=Math.max(0,Math.min(f-1,d)),m=d>=0&&d<f;if(this.magnetMode&&(s=e.b(d,r)),p!==this.lastCallbackBarIndex&&(this.pendingBarIndex=p,this.pendingPoint={x:s,y:c},this.lastCallbackBarIndex=p,this.scheduleCallback()),!u||!a)return;let h=ce(i);this.magnetMode&&m&&Cf(n,s,r,h.vertical.color),wf(n,s,o,h.vertical);let g=h.horizontal;if(g.visible){n.setLineDash((0,t.lineDash)(g.style,Sf,g.width)),n.strokeStyle=g.color;let r=e._(n,c,g.width);n.lineWidth=r.width,n.beginPath(),n.moveTo(o.x,r.y),n.lineTo(o.x+o.width,r.y),n.stroke()}n.setLineDash([])}renderAxisLabels(n,r,i,a,o,s=[],c=[]){if(this.mode===`hidden`)return;if(!this.position){this.syncedSlot!==null&&this.renderSyncedTimeLabel(n,r,i,a,this.syncedSlot,o,c);return}let{chartRect:u}=r,{x:d,y:f}=this.position;if(d<u.x||d>u.x+u.width||f<u.y||f>u.y+u.height)return;let p=e.A(d,r);this.magnetMode&&(d=e.b(p,r));let m=`600 ${i.font.sizeSmall}px ${i.font.family}`,h=l(e.M(f,r),r,this.pricePrecision??(0,t.autoPricePrecision)(r.priceRange.min,r.priceRange.max),this.locale),g=u.x+u.width;Of(n,s,f,g,r.priceAxisWidth??t.PRICE_AXIS_WIDTH,i,this.spanTints),kf(n,{text:h,anchorX:g,anchorY:f,orientation:`right`,bg:ce(i).labelBackground,fg:ce(i).labelText,theme:i,font:m}),this.drawTimePill(n,r,i,a,p,d,o,c)}beginSpans(){this.spanTints=[]}renderSpan(e,n,r,i,a,o){let s=`600 ${i.font.sizeSmall}px ${i.font.family}`,c=(0,t.withAlpha)(n.color,bf),l=vf(n.color);n.prices.length>0&&this.renderPriceSpan(e,n,i,s,c,l,r),n.times.length>0&&this.renderTimeSpan(e,n,r,i,a,s,c,l,o)}renderPriceSpan(n,r,i,a,o,s,c){let u=r.viewport,d=u.chartRect,f=d.x+d.width,p=u.priceAxisWidth??t.PRICE_AXIS_WIDTH,m=r.prices.map(t=>e.T(t,u)),h=u===c?this.pricePrecision??(0,t.autoPricePrecision)(u.priceRange.min,u.priceRange.max):b(x(u.priceRange.min,u.priceRange.max,d.height));n.save(),n.beginPath(),n.rect(f,d.y,p,d.height),n.clip(),m.length>1&&(n.fillStyle=o,n.fillRect(f,Math.min(...m),p,Math.abs(m[m.length-1]-m[0])),u===c&&this.spanTints.push({axis:`price`,from:Math.min(...m),to:Math.max(...m),tint:o})),r.prices.forEach((e,t)=>{let o=m[t];o<d.y||o>d.y+d.height||kf(n,{text:l(e,u,h,this.locale),anchorX:f,anchorY:o,orientation:`right`,bg:r.color,fg:s,theme:i,font:a})}),n.restore()}renderTimeSpan(n,r,i,a,o,s,c,l,u){let d=i.chartRect,f=u??d.y+d.height,p=r.times.map(t=>e.O(t,i));n.save(),n.beginPath(),n.rect(d.x,f,d.width,t.TIME_AXIS_HEIGHT),n.clip(),p.length>1&&(n.fillStyle=c,n.fillRect(Math.min(...p),f,Math.abs(p[p.length-1]-p[0]),t.TIME_AXIS_HEIGHT),this.spanTints.push({axis:`time`,from:Math.min(...p),to:Math.max(...p),tint:c})),r.times.forEach((e,t)=>{let i=p[t];i<d.x||i>d.x+d.width||kf(n,{text:this.formatTime(e,o),anchorX:i,anchorY:f,orientation:`bottom`,bg:r.color,fg:l,theme:a,font:s})}),n.restore()}renderSynced(t,n,r,i){let a=e.b(i,n),{chartRect:o}=n;if(a<o.x||a>o.x+o.width)return;let s=ce(r);this.magnetMode&&i>=0&&i<this.series().length&&Cf(t,a,n,s.vertical.color),wf(t,a,o,s.vertical)}renderSyncedTimeLabel(t,n,r,i,a,o,s=[]){let c=e.b(a,n),{chartRect:l}=n;c<l.x||c>l.x+l.width||this.drawTimePill(t,n,r,i,a,c,o,s)}formatTime(e,t){return this.timeText(e,ai(t))}timeText(e,n){return this.timeFormatter?this.timeFormatter(e*(0,t.barTimeUnit)(n),{kind:`crosshair`,timeZone:this.tz}):Af(e*(0,t.barTimeUnit)(n),this.tz,(0,t.barsAreDaily)(n),this.exchangeZone)}drawTimePill(t,n,r,i,a,o,s,c=[]){if(i.length===0||!this.timesPastData&&(a<0||a>=i.length))return;let l=ai(i),u=e.y(a,l),d=this.timeText(u,l),f=`600 ${r.font.sizeSmall}px ${r.font.family}`,p=s??n.chartRect.y+n.chartRect.height;t.font=f;let m=Math.ceil(t.measureText(d).width)/2+Ef;Df(t,c,o-m,o+m,p,r,this.spanTints),kf(t,{text:d,anchorX:o,anchorY:p,orientation:`bottom`,bg:ce(r).labelBackground,fg:ce(r).labelText,theme:r,font:f})}scheduleCallback(){this.callbackScheduled||(this.callbackScheduled=!0,queueMicrotask(()=>{this.callbackScheduled=!1,this.flushCallback(this.pendingBarIndex,this.pendingPoint)}))}flushCallback(e,t){this.callback?.(e,t)}},Sf=[4,4];function Cf(e,t,n,r){let i=n.barWidth+n.barSpacing;e.fillStyle=r,e.globalAlpha=.08,e.fillRect(t-i/2,n.chartRect.y,i,n.chartRect.height),e.globalAlpha=1}function wf(n,r,i,a){if(!a.visible)return;n.setLineDash((0,t.lineDash)(a.style,Sf,a.width)),n.strokeStyle=a.color;let o=e.g(n,r,a.width);n.lineWidth=o.width,n.beginPath(),n.moveTo(o.x,i.y),n.lineTo(o.x,i.y+i.height),n.stroke(),n.setLineDash([])}var Tf=20,Ef=8;function Df(e,t,n,r,i,a,o=[]){let s=t.filter(e=>e.right>n-2&&e.left<r+2);if(s.length===0)return;e.save();let c=a.font.sizeSmall+12;for(let t of s){let n=t.left-2,r=t.right-t.left+4;e.fillStyle=a.background,e.fillRect(n,i+1,r,c);for(let t of o){if(t.axis!==`time`)continue;let a=Math.max(n,t.from),o=Math.min(n+r,t.to);o<=a||(e.fillStyle=t.tint,e.fillRect(a,i+1,o-a,c))}}e.restore()}function Of(e,t,n,r,i,a,o=[]){let s=Math.ceil(a.font.sizeSmall/2)+1,c=t.filter(e=>Math.abs(e-n)<Tf/2+s);if(c.length!==0){e.save();for(let t of c){e.fillStyle=a.background,e.fillRect(r+1,t-s,i-1,s*2);for(let n of o){if(n.axis!==`price`)continue;let a=Math.max(t-s,n.from),o=Math.min(t+s,n.to);o<=a||(e.fillStyle=n.tint,e.fillRect(r+1,a,i-1,o-a))}}e.restore()}}function kf(e,t){e.save(),e.font=t.font;let n=Ef,r=Math.ceil(e.measureText(t.text).width)+n*2,i=Tf;if(e.fillStyle=t.bg,e.textBaseline=`middle`,t.orientation===`right`){let a=t.anchorX+5;O(e,a,t.anchorY-i/2,r,i,t.theme),e.beginPath(),e.moveTo(t.anchorX,t.anchorY),e.lineTo(a+2,t.anchorY-5),e.lineTo(a+2,t.anchorY+5),e.closePath(),e.fill(),e.fillStyle=t.fg,e.textAlign=`left`,e.fillText(t.text,a+n,t.anchorY)}else{let n=t.anchorX-r/2,a=t.anchorY+5;O(e,n,a,r,i,t.theme),e.beginPath(),e.moveTo(t.anchorX,t.anchorY),e.lineTo(t.anchorX-5,a+1),e.lineTo(t.anchorX+5,a+1),e.closePath(),e.fill(),e.fillStyle=t.fg,e.textAlign=`center`,e.fillText(t.text,t.anchorX,a+i/2)}e.restore()}function Af(e,n,r,i){if(r){let r=(0,t.barDateParts)(e,n,i);return`${r.month}/${r.day}/${r.year}`}let a=(0,t.timeParts)(e,n),{year:o,month:s,day:c,hours:l,minutes:u}=a;return r===void 0&&(0,t.isDateOnly)(a)?`${s}/${c}/${o}`:`${s}/${c} ${l<10?`0`+l:l}:${u<10?`0`+u:u}`}var jf=[`cross`,`dot`,`arrow`];function Mf(e){return typeof e==`string`&&jf.includes(e)}var Nf=9,Pf=3,Ff=1.5;function If(e){return e.replace(/['"<>&]/g,``)}function Lf(e,t,n){if(e===`arrow`)return`default`;if(e===`cross`)return`crosshair`;let r=Nf/2,i=`<svg xmlns='http://www.w3.org/2000/svg' width='${Nf}' height='${Nf}'><circle cx='${r}' cy='${r}' r='${Pf}' fill='${If(t)}' stroke='${If(n)}' stroke-width='${Ff}'/></svg>`,a=Math.floor(r);return`url("data:image/svg+xml,${encodeURIComponent(i)}") ${a} ${a}, crosshair`}var Rf=class{callbacks;enabled=!0;constructor(e){this.callbacks=e}setEnabled(e){this.enabled=e}handleKey(e){if(!this.enabled)return!1;let t=e.shiftKey?10:1;switch(e.key){case`ArrowLeft`:return this.callbacks.scrollBars(-t),!0;case`ArrowRight`:return this.callbacks.scrollBars(t),!0;case`ArrowUp`:case`+`:case`=`:return this.callbacks.zoom(.1),!0;case`ArrowDown`:case`-`:return this.callbacks.zoom(-.1),!0;case`Home`:return this.callbacks.goToStart(),!0;case`End`:return this.callbacks.goToEnd(),!0;case` `:return this.callbacks.fitContent(),!0;default:return!1}}},zf=16,Bf=80,Vf=864e5,Hf={month:`short`,day:`numeric`},Uf={month:`short`,day:`numeric`,year:`numeric`};function Wf(e,n,r,i){return(0,t.zonedDateFormatter)(r,i?Uf:Hf,n)(e)}var Gf=e=>e<10?`0${e}`:`${e}`;function Kf(e,n,r,i=`en-US`,a,o){let s=(0,t.normalizeBarTime)(e,a),c=(0,t.timeParts)(s,n);if(r!==void 0&&r>0?r>=Vf:(0,t.isDateOnly)(c))return Wf(s,(0,t.barDateZone)(s,n,o),i,!0);let l=Wf(s,n,i,!1),u=`${Gf(c.hours)}:${Gf(c.minutes)}`;return r!==void 0&&r>0&&r<6e4?`${l} · ${u}:${Gf(new Date(s).getUTCSeconds())}`:`${l} · ${u}`}var qf=1e4;function Jf(e,n){return Number.isFinite(e)?(0,t.usesKoreanUnits)(n)&&e>=qf?(0,t.formatVolumeLoc)(e,n):(0,t.usesKoreanUnits)(n)?(0,t.formatPrice)(e,e%1==0?0:2,n):e>=1e9?`${(0,t.formatPrice)(e/1e9,2,n)}B`:e>=1e6?`${(0,t.formatPrice)(e/1e6,2,n)}M`:e>=1e3?`${(0,t.formatPrice)(e/1e3,1,n)}K`:(0,t.formatPrice)(e,e%1==0?0:2,n):`—`}var Yf=class{el=null;visible=!1;appliedTheme=null;locale=`en-US`;pricePrecision=null;tz=null;exchangeZone=null;priceFormatter=null;timeFormatter=null;dirEl;timeEl;changeEl;valueEls;labelEls=[];dividerEl;width=176;height=112;create(e){if(this.el)return;let t=document.createElement(`div`);t.setAttribute(`aria-hidden`,`true`),Object.assign(t.style,{position:`absolute`,left:`0`,top:`0`,display:`none`,minWidth:`168px`,padding:`8px 10px 9px`,borderRadius:`var(--tcw-tooltip-radius, 8px)`,fontSize:`11.5px`,lineHeight:`1.45`,fontVariantNumeric:`tabular-nums`,pointerEvents:`none`,zIndex:`100`,whiteSpace:`nowrap`,willChange:`transform`,contain:`layout paint`,backdropFilter:`blur(10px)`}),n(t);let r=Xf({display:`flex`,alignItems:`center`,gap:`7px`,marginBottom:`6px`});this.dirEl=Xf({width:`3px`,height:`12px`,borderRadius:`2px`,flex:`none`}),this.timeEl=Xf({flex:`1`,fontSize:`11px`,letterSpacing:`0.01em`}),this.changeEl=Xf({padding:`1px 6px`,borderRadius:`999px`,fontSize:`10.5px`,fontWeight:`600`}),r.append(this.dirEl,this.timeEl,this.changeEl);let i=Xf({display:`grid`,gridTemplateColumns:`auto 1fr auto 1fr`,columnGap:`8px`,rowGap:`1px`,alignItems:`baseline`}),a=e=>{let t=Xf({fontSize:`10px`,letterSpacing:`0.04em`});t.textContent=e,this.labelEls.push(t);let n=Xf({textAlign:`right`,fontWeight:`500`});return i.append(t,n),n},o=a(`O`),s=a(`H`),c=a(`L`),l=a(`C`);this.dividerEl=Xf({height:`1px`,margin:`6px 0 5px`});let u=Xf({display:`flex`,justifyContent:`space-between`,gap:`12px`}),d=Xf({fontSize:`10px`,letterSpacing:`0.04em`});d.textContent=`VOL`,this.labelEls.push(d);let f=Xf({fontWeight:`500`});u.append(d,f),this.valueEls={open:o,high:s,low:c,close:l,volume:f},t.append(r,i,this.dividerEl,u),e.appendChild(t),this.el=t}setLocale(e){this.locale=e}setPricePrecision(e){this.pricePrecision=e}setTimezoneOffset(e){this.tz=e}setExchangeTimeZone(e){this.exchangeZone=e}setPriceFormatter(e){this.priceFormatter=e}setTimeFormatter(e){this.timeFormatter=e}show(e,n,r,i,a={}){let o=this.el;if(!o)return;this.appliedTheme!==r&&this.applyTheme(r);let s=this.pricePrecision??(a.priceRange?(0,t.autoPricePrecision)(a.priceRange.min,a.priceRange.max):(0,t.autoPricePrecision)(n.low,n.high)),c=e=>this.priceFormatter?.(e)??(0,t.formatPrice)(e,s,this.locale),l=a.prevClose??n.open,u=n.close-l,d=l===0?0:u/l*100,f=u>=0,p=f?r.candleUp:r.candleDown,m=f?`+`:`−`;this.timeEl.textContent=this.timeFormatter?this.timeFormatter((0,t.normalizeBarTime)(n.time,a.timeUnit),{kind:`crosshair`,timeZone:this.tz}):Kf(n.time,this.tz,a.barStepMs,this.locale,a.timeUnit,this.exchangeZone),this.changeEl.textContent=`${m}${(0,t.formatPrice)(Math.abs(d),2,this.locale)}%`,this.changeEl.style.color=p,this.changeEl.style.background=$f(p,.14),this.dirEl.style.background=n.close>=n.open?r.candleUp:r.candleDown,this.valueEls.open.textContent=c(n.open),this.valueEls.high.textContent=c(n.high),this.valueEls.low.textContent=c(n.low),this.valueEls.close.textContent=c(n.close),this.valueEls.close.style.color=n.close>=n.open?r.candleUp:r.candleDown,this.valueEls.volume.textContent=Jf(n.volume,this.locale),this.visible||=(o.style.display=`block`,!0),this.width=o.offsetWidth||this.width,this.height=o.offsetHeight||this.height;let h=a.plot??{x:0,y:0,width:i.width-Bf,height:i.height},g=h.x+h.width,_=h.y+h.height,v=e.x+zf,y=e.y-this.height/2;v+this.width>g-4&&(v=e.x-this.width-zf),v<h.x+4&&(v=h.x+4),y+this.height>_-4&&(y=_-this.height-4),y<h.y+4&&(y=h.y+4),o.style.transform=`translate(${Math.round(v)}px, ${Math.round(y)}px)`}hide(){this.el&&this.visible&&(this.el.style.display=`none`,this.visible=!1)}isVisible(){return this.visible}destroy(){this.el?.remove(),this.el=null,this.visible=!1,this.appliedTheme=null,this.labelEls=[]}applyTheme(e){let t=this.el,n=Zf(e.background);t.style.background=$f(e.background,n?.9:.94),t.style.border=`1px solid ${e.axisLine}`,t.style.boxShadow=n?`0 12px 32px -8px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.35)`:`0 12px 32px -10px rgba(15, 19, 26, 0.22), 0 2px 6px rgba(15, 19, 26, 0.08)`,t.style.color=e.text,t.style.fontFamily=e.font.family,this.timeEl.style.color=e.textSecondary;for(let t of this.labelEls)t.style.color=e.textSecondary;this.dividerEl.style.background=e.axisLine,this.appliedTheme=e}};function Xf(e){let t=document.createElement(`div`);return Object.assign(t.style,e),t}function Zf(e){let t=Qf(e);return t?(.299*t[0]+.587*t[1]+.114*t[2])/255<.5:!0}function Qf(e){if(e.startsWith(`#`)){let t=e.slice(1),n=t.length===3?t.split(``).map(e=>e+e).join(``):t.slice(0,6);return[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)]}let t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);return t?[Number(t[1]),Number(t[2]),Number(t[3])]:null}function $f(e,t){let n=Qf(e);return n?`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${t})`:`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`}var ep=2,tp=2,np=`0.7`,rp=class{el=null;deltaEl=null;timeEl=null;ohlcEl=null;pinnedBar=null;pinnedIndex=-1;tz=null;exchangeZone=null;priceFormatter=null;pricePrecision=null;locale=`en-US`;setTimezone(e){this.tz=e}setExchangeTimeZone(e){this.exchangeZone=e}setPriceFormatter(e){this.priceFormatter=e}setPricePrecision(e){this.pricePrecision=e!==null&&Number.isInteger(e)&&e>=0?e:null}setLocale(e){this.locale=e}fmt(e){return this.priceFormatter?this.priceFormatter(e):(0,t.formatPrice)(e,this.pricePrecision??ep,this.locale)}create(e){if(this.el)return;this.el=document.createElement(`div`),Object.assign(this.el.style,{position:`absolute`,display:`none`,padding:`6px 10px`,borderRadius:`var(--tcw-tooltip-radius, 4px)`,fontSize:`11px`,fontFamily:`-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif`,lineHeight:`1.5`,pointerEvents:`auto`,cursor:`pointer`,zIndex:`99`,whiteSpace:`nowrap`,willChange:`transform`}),n(this.el),this.timeEl=document.createElement(`div`),this.ohlcEl=document.createElement(`div`),this.deltaEl=document.createElement(`div`),this.deltaEl.style.marginTop=`4px`,this.deltaEl.style.paddingTop=`4px`,this.deltaEl.style.borderTop=`1px solid currentColor`,this.deltaEl.style.opacity=`0.85`,this.deltaEl.style.fontVariantNumeric=`tabular-nums`,this.el.appendChild(this.timeEl),this.el.appendChild(this.ohlcEl),this.el.appendChild(this.deltaEl);let r=document.createElement(`div`);r.innerHTML=`${(0,t.iconSvg)(t.UI_ICONS.pin,10)}<span>pinned</span>`,r.style.display=`flex`,r.style.alignItems=`center`,r.style.gap=`3px`,r.style.fontSize=`9px`,r.style.opacity=`0.6`,r.style.marginBottom=`2px`,r.style.letterSpacing=`0.04em`,r.style.textTransform=`uppercase`,this.el.insertBefore(r,this.timeEl),e.appendChild(this.el)}pin(e,n,r,i,a=!1){if(!this.el||!this.timeEl||!this.ohlcEl)return;this.pinnedBar=e,this.pinnedIndex=n;let o=e.close>=e.open?r.candleUp:r.candleDown,s=(0,t.normalizeBarTime)(e.time,i),c=a?(0,t.barDateParts)(s,this.tz,this.exchangeZone):(0,t.timeParts)(s,this.tz);this.timeEl.textContent=a?`${c.month}/${c.day}/${c.year}`:`${c.month}/${c.day} ${ip(c.hours)}:${ip(c.minutes)}`,this.timeEl.style.color=r.textSecondary;let l=[];for(let[t,n]of[[`O `,e.open],[` H `,e.high],[` L `,e.low],[` C `,e.close]]){let e=document.createElement(`span`);e.style.opacity=`.6`,e.textContent=t;let r=document.createElement(`span`);r.style.color=o,r.textContent=this.fmt(n),l.push(e,r)}this.ohlcEl.replaceChildren(...l);let u=ap(r.background);this.el.style.background=op(r.background,u?.96:.97),this.el.style.border=`1px solid ${o}`,this.el.style.boxShadow=u?`0 4px 12px rgba(0,0,0,0.55)`:`0 4px 12px rgba(0,0,0,0.18)`,this.el.style.color=r.text,this.el.style.backdropFilter=`blur(8px)`,this.el.style.display=`block`}unpin(){this.pinnedBar=null,this.pinnedIndex=-1,this.el&&(this.el.style.display=`none`)}isPinned(){return this.pinnedBar!==null}getPinnedIndex(){return this.pinnedIndex}reposition(n,r,i,a){if(!this.el||!this.pinnedBar)return;let o=e.b(this.pinnedIndex,n),s=e.T(this.pinnedBar.close,n),c=n.chartRect,l=o>=c.x-4&&o<=c.x+c.width+4;this.el.style.opacity=l?`1`:`0.35`;let u=Math.max(c.x,Math.min(c.x+c.width-180,o+8)),d=Math.max(c.y,Math.min(c.y+c.height-90,s-64));if(this.el.style.transform=`translate(${Math.round(u)}px, ${Math.round(d)}px)`,this.el.style.left=`0`,this.el.style.top=`0`,this.deltaEl)if(r&&i!==null&&i!==this.pinnedIndex){let e=r.close-this.pinnedBar.close,n=this.pinnedBar.close===0?0:e/this.pinnedBar.close*100,o=e>0?`+`:e<0?`−`:``,s=i-this.pinnedIndex,c=e>=0?a.candleUp:a.candleDown;this.deltaEl.style.color=c;let l=(0,t.formatPrice)(Math.abs(n),tp,this.locale),u=document.createElement(`span`);u.style.opacity=np,u.textContent=`(${o}${l}%)`,this.deltaEl.replaceChildren(`Δ ${o}${this.fmt(Math.abs(e))} `,u,` · ${s>0?`+`:``}${s} bars`),this.deltaEl.style.display=`block`}else this.deltaEl.style.display=`none`}destroy(){this.el?.remove(),this.el=null,this.deltaEl=null,this.timeEl=null,this.ohlcEl=null,this.pinnedBar=null,this.pinnedIndex=-1}};function ip(e){return e<10?`0`+e:``+e}function ap(e){if(e.startsWith(`#`)){let t=e.slice(1),n=t.length===3?t.split(``).map(e=>e+e).join(``):t.slice(0,6),r=parseInt(n.slice(0,2),16),i=parseInt(n.slice(2,4),16),a=parseInt(n.slice(4,6),16);return(.299*r+.587*i+.114*a)/255<.5}return!0}function op(e,t){if(e.startsWith(`#`)){let n=e.slice(1),r=n.length===3?n.split(``).map(e=>e+e).join(``):n.slice(0,6);return`rgba(${parseInt(r.slice(0,2),16)}, ${parseInt(r.slice(2,4),16)}, ${parseInt(r.slice(4,6),16)}, ${t})`}return e}var sp=class{listeners=new Map;tauriBridge=null;on(e,t){let n=this.listeners.get(e);n||(n=new Set,this.listeners.set(e,n)),n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}hasListeners(e){return(this.listeners.get(e)?.size??0)>0}emit(e,t){let n={type:e,timestamp:Date.now(),payload:t},r=this.listeners.get(e);if(r)for(let e of r)e(n);if(this.tauriBridge?.enabled&&window.__TAURI__){let t=this.tauriBridge.eventPrefix??`tc-chart`;window.__TAURI__.event.emit(`${t}:${e}`,n).catch(()=>{})}}enableTauriBridge(e){this.tauriBridge=e}disableTauriBridge(){this.tauriBridge=null}destroy(){this.listeners.clear(),this.tauriBridge=null}},cp=1.5,lp=1.5,up=1,dp=2.5,fp=.7,pp=4,mp=.2,hp={primary:null,hover:null,drag:null};function gp(e){hp=e??{primary:null,hover:null,drag:null}}function _p(e,t,n){return(Math.round(e*t+n-.5)+.5-n)/t}function vp(e,t,n,r){e.beginPath(),e.arc(t,n,r,0,Math.PI*2)}function yp(e,n,r,i={}){let a=M(),o=n.style.color,s=e.getTransform?.()??{a:1,d:1,e:0,f:0},c=n.id===hp.primary&&!n.locked;e.save(),e.setLineDash([]),r.forEach((r,l)=>{let u=_p(r.x,s.a||1,s.e??0),d=_p(r.y,s.d||1,s.f??0),f=An(n.style.lineWidth)+lp;if(hn(u-f,d-f,f*2,f*2),!c){vp(e,u,d,dp*a.scale),e.globalAlpha=fp,e.fillStyle=o,e.fill(),e.globalAlpha=1;return}let p=An(n.style.lineWidth)-(i.sides?.has(l)?up:0),m=hp.drag?.id===n.id&&hp.drag.index===l,h=!m&&hp.hover?.id===n.id&&hp.hover.index===l||m?p+lp:p;m&&(vp(e,u,d,h+pp),e.fillStyle=(0,t.withAlpha)(o,mp),e.fill()),vp(e,u,d,h),e.fillStyle=m?o:a.handleFill,e.fill(),e.strokeStyle=m?a.background:o,e.lineWidth=cp,e.stroke()}),e.restore()}function bp(e){return e?.anchoring===`screen`}var xp=24;function Sp(e,t,n){return Math.max(t,Math.min(e,Math.max(t,n)))}function Cp(e,t){let n=t.chartRect;return{x:Sp(n.x+e.time*n.width,n.x,n.x+n.width-xp),y:Sp(n.y+e.price*n.height,n.y+xp,n.y+n.height-xp)}}function wp(e){let t=e=>Number.isFinite(e)?Math.min(1,Math.max(0,e)):0;return e.map(e=>({time:t(e.time),price:t(e.price)}))}function Tp(e,t){let n=t.chartRect,r=(e,t)=>t>0?Math.min(1,Math.max(0,e/t)):0;return{time:r(e.x-n.x,n.width),price:r(e.y-n.y,n.height)}}function Ep(e,t,n,r){return e.map(e=>{let i=Cp(e,r);return Tp({x:i.x+t,y:i.y+n},r)})}function Dp(e,t){let n=e=>Math.min(1,Math.max(0,e+t<=1?e+t:e-t));return e.map(e=>({time:n(e.time),price:n(e.price)}))}var Op={at:e=>e,value:e=>e,price:e=>e};function kp(t){if(!t)return Op;let{min:n,max:r}=t.priceRange,i=t.logScale===!0&&n>0&&r>0;return{at:n=>e.D(n,t),value:i?e=>Math.log(Math.max(e,2**-52)):e=>e,price:i?Math.exp:e=>e}}function Ap(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;if(a===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function jp(e,t,n,r=!1){for(let r=0;r<t.length-1;r++)if(Ap(e,t[r],t[r+1])<=n)return!0;return r&&t.length>2&&Ap(e,t[t.length-1],t[0])<=n}function Mp(e,t){switch(e.kind){case`boolean`:return typeof t==`boolean`;case`number`:return typeof t==`number`&&Number.isFinite(t);case`levels`:return Array.isArray(t);default:return typeof t==`string`}}var Np=.55,J=class{hitTestAnchor(e,t,n,r){let i=-1,a=1/0,o=this.handlePoints(t,n);for(let t=0;t<o.length;t++){let n=o[t],s=Math.hypot(e.x-n.x,e.y-n.y);s<=r&&s<a&&(i=t,a=s)}return i}option(e,t){let n=this.descriptor.options?.[t],r=e.options?.[t];return n?r!==void 0&&Mp(n,r)?r:n.default:r}optionsOf(e){return t=>this.option(e,t)}visibleLevels(e,t=`levels`){return this.option(e,t).filter(e=>e.visible&&Number.isFinite(e.value))}extendLine(e,t,n,r,i){let a=t.x-e.x,o=t.y-e.y,s=Math.hypot(a,o);if(s===0||!r&&!i)return[e,t];let c=Math.hypot(n.chartRect.width,n.chartRect.height)*2,l=a/s*c,u=o/s*c;return[r?{x:e.x-l,y:e.y-u}:e,i?{x:t.x+l,y:t.y+u}:t]}linePriceAt(e,t,n,r,i,a=Op){let o=this.lineValueAt(e,t,n,r,i,a);return o===null?null:a.price(o)}lineValueAt(e,t,n,r,i,a){let o=a.at(e.time),s=a.at(t.time);if(o===s)return null;let c=(a.at(n)-o)/(s-o);if(!Number.isFinite(c)||c<0&&!r||c>1&&!i)return null;let l=a.value(e.price);return l+(a.value(t.price)-l)*c}anchorToPixel(t,n){return bp(this.descriptor)?Cp(t,n):{x:e.O(t.time,n),y:e.T(t.price,n)}}pixelToAnchor(t,n){return bp(this.descriptor)?Tp(t,n):{time:e.j(t.x,n),price:e.M(t.y,n)}}applyLineStyle(e,t){e.strokeStyle=t.color,e.lineWidth=t.lineWidth,e.lineCap=t.lineStyle===`dashed`?`butt`:`round`,e.lineJoin=`round`,e.setLineDash(Pn(t.lineStyle,t.lineWidth))}strokeHorizontal(t,n,r,i){let a=e._(t,i,Number(t.lineWidth)||1);t.lineWidth=a.width,t.beginPath(),t.moveTo(n,a.y),t.lineTo(r,a.y),t.stroke()}strokeVertical(t,n,r,i){let a=e.g(t,n,Number(t.lineWidth)||1);t.lineWidth=a.width,t.beginPath(),t.moveTo(a.x,r),t.lineTo(a.x,i),t.stroke()}resetLineStyle(e){e.setLineDash([]),e.lineCap=`butt`,e.lineJoin=`miter`}handlePoints(e,t){return e.anchors.map(e=>this.anchorToPixel(e,t))}timeHandles(e,t){let n=t.chartRect.y+t.chartRect.height/2;return e.anchors.map(e=>({x:this.anchorToPixel(e,t).x,y:n}))}strokeCrispRect(e,t,n,r,i){let a=Math.min(t,t+r),o=Math.max(t,t+r),s=Math.min(n,n+i),c=Math.max(n,n+i);this.strokeHorizontal(e,a,o,s),this.strokeHorizontal(e,a,o,c),this.strokeVertical(e,a,s,c),this.strokeVertical(e,o,s,c)}applyGuideStyle(e,t,n=!1){e.strokeStyle=t,e.lineWidth=1,e.lineCap=`butt`,e.globalAlpha=Np,e.setLineDash(n?Pn(`guide`,1):[])}renderAnchorHandles(e,t,n){yp(e,t,this.handlePoints(t,n))}distanceToLine(e,t,n){return Ap(e,t,n)}distanceToInfiniteLine(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=Math.hypot(r,i);return a===0?Math.hypot(e.x-t.x,e.y-t.y):Math.abs(r*(t.y-e.y)-i*(t.x-e.x))/a}};function Pp(e){if(typeof e!=`string`)return;let t=e.trim().slice(0,80);return t.length>0?t:void 0}function Fp(e){let t={};for(let[n,r]of Object.entries(e))t[n]=Array.isArray(r)?r.map(e=>({...e})):r;return t}function Y(e){return{...e,anchors:e.anchors.map(e=>({...e})),style:{...e.style},options:e.options?Fp(e.options):void 0,intervals:e.intervals?Na(e.intervals):void 0,group:e.group?{...e.group}:void 0,meta:e.meta?{...e.meta}:void 0}}function Ip(e,t){return JSON.stringify(e??{})===JSON.stringify(t??{})}function Lp(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n].time!==t[n].time||e[n].price!==t[n].price)return!1;return!0}var Rp=1,zp=1,Bp=/^tc_drawing_(\d+)$/,Vp=/^tc_group_(\d+)$/;function Hp(){return`tc_drawing_${Rp++}`}function Up(){let e=zp++;return{id:`tc_group_${e}`,number:e}}function Wp(e){for(let t of e){let e=Bp.exec(t.id);e&&(Rp=Math.max(Rp,Number(e[1])+1));let n=t.group?Vp.exec(t.group.id):null;n&&(zp=Math.max(zp,Number(n[1])+1))}}function Gp(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Set(t);return[...t.map(e=>n.get(e)).filter(e=>e!==void 0),...e.filter(e=>!r.has(e.id))]}function Kp(e,t,n){let r=t-1;if(typeof n==`number`)return Number.isInteger(n)?Math.min(r,Math.max(0,n)):e;switch(n){case`front`:return r;case`back`:return 0;case`forward`:return Math.min(r,e+1);case`backward`:return Math.max(0,e-1)}}function qp(e,t){return e.map(e=>e.id===t.id?structuredClone(t):e)}function Jp(e,t){switch(t.type){case`drawingBatch`:return[...t.actions??[]].reverse().reduce(Jp,[...e]);case`drawingCreate`:return t.after?e.filter(e=>e.id!==t.after.id):[...e];case`drawingRemove`:{if(!t.before)return[...e];let n=[...e];return n.splice(Math.min(t.index??n.length,n.length),0,structuredClone(t.before)),n}case`drawingOrder`:return t.order?Gp(e,t.order.before):[...e];case`drawingModify`:return t.before?qp(e,t.before):[...e];default:return[...e]}}function Yp(e,t){switch(t.type){case`drawingBatch`:return(t.actions??[]).reduce(Yp,[...e]);case`drawingCreate`:return t.after?[...e,structuredClone(t.after)]:[...e];case`drawingRemove`:return t.before?e.filter(e=>e.id!==t.before.id):[...e];case`drawingOrder`:return t.order?Gp(e,t.order.after):[...e];case`drawingModify`:return t.after?qp(e,t.after):[...e];default:return[...e]}}var Xp={"]":[`forward`,`front`],"}":[`front`,`front`],"[":[`backward`,`back`],"{":[`back`,`back`]};function Zp(e,t,n){if(e===`Escape`)return`escape`;if(e===`Enter`&&!t)return`finish`;if(e===`Delete`||e===`Backspace`)return`delete`;if(!t)return null;let r=n??(e.length===1&&e!==e.toLowerCase()),i=Xp[e];if(i)return i[+!!r];switch(e.toLowerCase()){case`c`:return`copy`;case`v`:return`paste`;case`d`:return`duplicate`;case`g`:return r?`ungroup`:`group`;case`z`:return r?`redo`:`undo`;case`y`:return`redo`;default:return null}}var Qp=2,$p=6;function em(e){return e.descriptor.creation??`clicks`}var tm=class{drawing=null;plugin=null;preview=null;lastPos=null;dragging=!1;step=Qp;get current(){return this.drawing}reset(){this.drawing=null,this.plugin=null,this.preview=null,this.lastPos=null,this.dragging=!1,this.step=Qp}press(e,t,n,r,i){if(this.dragging)return`continue`;let a=em(e);if(!this.drawing)return this.plugin=e,this.drawing={...t(),anchors:[n]},this.preview=null,this.lastPos=r,a===`freehand`?(this.dragging=!0,`continue`):a===`clicks`&&e.descriptor.requiredAnchors<=1?`done`:`continue`;let o=this.drawing.anchors[this.drawing.anchors.length-1],s=i?i(o):this.lastPos;if(a===`path`&&s&&Math.hypot(r.x-s.x,r.y-s.y)<=$p)return this.finish();this.commit(n,r);let c=a===`path`?e.descriptor.maxAnchors??100:e.descriptor.requiredAnchors;return this.drawing.anchors.length>=c?`done`:`continue`}move(e,t){if(!this.drawing||!this.plugin)return!1;if(this.dragging){let n=this.lastPos;return n&&Math.hypot(t.x-n.x,t.y-n.y)<this.step?!0:(this.drawing.anchors.length>=2e3&&(this.drawing.anchors=this.drawing.anchors.filter((e,t)=>t%2==0),this.step*=2),this.commit(e,t),!0)}return em(this.plugin)===`path`||this.drawing.anchors.length<this.plugin.descriptor.requiredAnchors?(this.preview=e,!0):!1}release(){return this.dragging?(this.dragging=!1,this.hasEnough()?`done`:`cancel`):null}undoPoint(){return!this.drawing||this.dragging||this.drawing.anchors.length<=1?(this.reset(),!1):(this.drawing.anchors.pop(),this.preview=null,this.lastPos=null,!0)}finish(){return!this.plugin||em(this.plugin)!==`path`||!this.hasEnough()?`continue`:(this.preview=null,`done`)}previewState(){return this.drawing?this.preview?{...this.drawing,anchors:[...this.drawing.anchors,this.preview]}:this.drawing:null}take(){let e=this.drawing;return this.reset(),e}hasEnough(){return!!this.drawing&&!!this.plugin&&this.drawing.anchors.length>=Math.max(2,this.plugin.descriptor.requiredAnchors)}commit(e,t){this.drawing.anchors.push(e),this.preview=null,this.lastPos=t}},nm=50;function rm(e,t,n,r,i){return im(e,t,n,r,e=>[r[e].open,r[e].high,r[e].low,r[e].close],i)}function im(t,n,r,i,a,o){if(r===`none`||i.length===0)return{time:t,price:n};let s=!!(o?.data&&o.data.length>0),c=Math.round(s?e.k(t,i):t);if(c<0||c>i.length-1)return{time:t,price:n};let l=s?i[c].time:c,u=a(c).filter(e=>Number.isFinite(e));if(u.length===0)return{time:l,price:n};let d=u[0];for(let e of u)Math.abs(n-e)<Math.abs(n-d)&&(d=e);return r===`magnet`&&o&&Math.abs(e.T(n,o)-e.T(d,o))>nm?{time:l,price:n}:{time:l,price:d}}var am=class{primaryId=null;others=new Set;listener=null;setListener(e){this.listener=e}change(e){let t=this.ids().join(`\0`),n=e();return this.listener&&this.ids().join(`\0`)!==t&&this.listener(this.ids()),n}get primary(){return this.primaryId}has(e){return e===this.primaryId||this.others.has(e)}ids(){return this.primaryId?[this.primaryId,...this.others]:[]}clear(){this.change(()=>{this.primaryId=null,this.others.clear()})}add(e){this.change(()=>{this.primaryId?e!==this.primaryId&&this.others.add(e):this.primaryId=e})}only(e,t=[]){this.change(()=>{this.primaryId=e,this.others.clear();for(let n of t)n!==e&&this.others.add(n)})}focus(e){e===this.primaryId||!this.others.has(e)||this.change(()=>{this.primaryId&&this.others.add(this.primaryId),this.others.delete(e),this.primaryId=e})}remove(e){return this.change(()=>this.removeNow(e))}removeNow(e){let t=!1;for(let n of e)this.others.delete(n)&&(t=!0),n===this.primaryId&&(this.primaryId=null,t=!0);if(!this.primaryId){let e=this.others.values().next();e.done||(this.primaryId=e.value,this.others.delete(e.value))}return t}},om=Math.PI/4,sm=new Set([`trendLine`,`ray`,`extendedLine`,`infoLine`,`trendAngle`,`arrow`,`horizontalRay`,`measure`,`priceRange`,`dateRange`,`dateAndPriceRange`,`path`,`polyline`,`fibRetracement`,`fibExtension`]);function cm(e){return sm.has(e)}function lm(e,t){let n=t.x-e.x,r=t.y-e.y;if(n===0&&r===0)return t;let i=Math.round(Math.atan2(r,n)/om)*om,a=Math.cos(i),o=Math.sin(i),s=n*a+r*o;return{x:e.x+um(s*a),y:e.y+um(s*o)}}function um(e){return Math.abs(e)<1e-9?0:e}function dm(t,n,r){let i=fm(t,r),a=lm(i,n);if(a.x===i.x)return{time:t.time,price:e.M(a.y,r)};let o=e.j(a.x,r);if(a.y===i.y)return{time:o,price:t.price};let s=e.O(o,r)-i.x;return{time:o,price:e.M(i.y+Math.sign(a.y-i.y)*Math.abs(s),r)}}function fm(t,n){return{x:e.O(t.time,n),y:e.T(t.price,n)}}function pm(e,t,n){let r=-1,i=1/0;return e.forEach((e,a)=>{let o=fm(e,n),s=Math.hypot(o.x-t.x,o.y-t.y);s<i&&(r=a,i=s)}),r}var mm=3,hm=class{start=null;handle=-1;grabbed=[];held=-1;constructor(e,t=()=>!1){this.find=e,this.onScreen=t}isActive(){return this.start!==null}activeHandle(){return this.start===null?-1:this.handle}beginMove(e,t){this.start=e,this.handle=-1,this.held=-1,this.grabbed=t.map(e=>({id:e.id,anchors:e.anchors.map(e=>({...e})),before:Y(e)}))}beginResize(e,t,n){this.start=e,this.handle=n,this.grabbed=[{id:t.id,anchors:t.anchors.map(e=>({...e})),before:Y(t)}]}move(e,t,n,r){return!this.start||this.grabbed.length===0?!1:this.handle>=0?this.reshape(e,t,n,r):this.translate(e,t,r)}end(){let e=this.grabbed.flatMap(({id:e,before:t})=>{let n=this.find(e);return n?[{before:t,drawing:n}]:[]});return this.start=null,this.handle=-1,this.grabbed=[],e}translate(e,t,n){let r=this.start,i=e.x-r.x,a=e.y-r.y;if(Math.hypot(i,a)<mm&&this.unmoved())return!0;let o=t.barWidth+t.barSpacing,s=o>0?Math.round(i/o):0,c=this.find(this.grabbed[0].id),l=n&&c&&!this.onScreen(c)?this.snapHeld(s,a,t,n):null;return l&&(a+=l.dy),this.grabbed.forEach(({id:n,anchors:o},c)=>{let u=this.find(n);if(!(!u||u.locked)){if(this.onScreen(u)){u.anchors=Ep(o,i,e.y-r.y,t);return}u.anchors=gm(o,s,a,t),c===0&&l&&(u.anchors[this.held]={...u.anchors[this.held],price:l.price})}}),!0}snapHeld(t,n,r,i){let a=this.grabbed[0];this.held<0&&(this.held=pm(a.anchors,this.start,r));let o=a.anchors[this.held];if(!o)return null;let[s]=gm([o],t,n,r),{price:c}=i.snap(s);return c===s.price?null:{price:c,dy:e.T(c,r)-e.T(s.price,r)}}unmoved(){return this.grabbed.every(({id:e,anchors:t})=>{let n=this.find(e)?.anchors;return!n||n.every((e,n)=>e.time===t[n]?.time&&e.price===t[n]?.price)})}reshape(n,r,i,a){let o=this.find(this.grabbed[0].id);if(!o)return!1;let s=this.onScreen(o)?Tp(n,r):a?a.handleAt(n,o,this.handle):{time:e.j(n.x,r),price:e.M(n.y,r)};if(i?.moveHandle){let e=i.moveHandle(Y(o),this.handle,s);o.anchors=e.anchors,o.options=e.options&&Object.keys(e.options).length>0?(0,t.sanitizeDrawingOptions)(i.descriptor.options,e.options):void 0}else this.handle<o.anchors.length&&(o.anchors[this.handle]=s);return!0}};function gm(t,n,r,i){let a=i.data,o=t=>{let r=e.D(t,i)+n;return a&&a.length>0?e.y(r,a):r};return t.map(t=>({time:n===0?t.time:o(t.time),price:r===0?t.price:e.M(e.T(t.price,i)+r,i)}))}function _m(e){let t=e.filter(Number.isFinite);if(t.length===0)return[];let n=Math.min(...t),r=Math.max(...t);return n===r?[n]:[n,r]}function vm(e,t){let n=t.axisSpan??`both`;if(n===`none`||t.anchoring===`screen`)return null;let r=n===`time`?[]:_m(e.anchors.map(e=>e.price)),i=n===`price`?[]:_m(e.anchors.map(e=>e.time));return r.length===0&&i.length===0?null:{prices:r,times:i}}var ym={drawings:[],pastes:0},bm=1e7,xm={line:8,handle:8},Sm=8,Cm=1e3,wm=.02;function Tm(e,t){return e.x>=t.x&&e.x<=t.x+t.width&&e.y>=t.y&&e.y<=t.y+t.height}function Em(e){return e.type===`indicators`||e.type===`custom`}function Dm(e){return(e.actions??[]).some(e=>Em(e)||Dm(e))}var Om=class{registry=new Map;drawings=[];state=`idle`;activeTool=null;activeStyle={color:`#4c8dff`,lineWidth:1,lineStyle:`solid`,fillColor:t.LINE_TINT_FILL,fillOpacity:.12};hoverHandle=null;extents=new Map;hoverDrawing=null;creator=new tm;finishedAt=-1/0;creationPressAt=-1/0;eraser=!1;selection=new am;drag=new hm(e=>this.drawings.find(t=>t.id===e),e=>this.onScreen(e.type));eventCallback=null;requestRender=null;undoRedo=null;magnetMode=`none`;mods={ctrl:!1,shift:!1};pendingCopy=null;copies=null;copiedFrom=[];copySources=new Map;lastNudge=null;dataGetter=null;dataRevision=()=>0;displayDataGetter=null;stayInDrawingMode=!1;toolAllowed=()=>!0;toolDefaults=new Map;edits=new Map;batch=null;timeframe=null;register(e){this.registry.set(e.descriptor.type,e),this.dataGetter&&e.setDataGetter?.(this.dataGetter,this.dataRevision)}setEventCallback(e){this.eventCallback=e}setRequestRender(e){this.requestRender=e}setUndoRedoManager(e){this.undoRedo=e}setMagnetMode(e){this.magnetMode=e}getMagnetMode(){return this.magnetMode}setModifiers(e){this.mods={ctrl:e.ctrl,shift:e.shift}}activeMagnet(){return!this.mods.ctrl||this.copies?this.magnetMode:this.magnetMode===`none`?`strong`:`none`}setDataGetter(e,t=()=>0){this.dataGetter=e,this.dataRevision=t;for(let n of this.registry.values())n.setDataGetter?.(e,t)}setDisplayDataGetter(e){this.displayDataGetter=e}panes=null;setPanes(e){this.panes=e}paneAt(e){return this.panes?this.panes.paneAt(e):void 0}viewportFor(e,t){if(e===void 0)return t;let n=this.panes?.viewportOf(e)??null;return n&&t.formatTime&&!n.formatTime?{...n,formatTime:t.formatTime}:n}scopeAt(e,t){if(!this.panes&&!Tm(e,t.chartRect))return null;let n=this.paneAt(e);if(n===null)return null;let r=this.viewportFor(n,t);return r?{pane:n,viewport:r}:null}renamePanes(e){let t=!1;this.drawings=this.drawings.map(n=>{let r=n.paneId===void 0?void 0:e.get(n.paneId);return r===void 0||r===n.paneId?n:(t=!0,{...n,paneId:r})}),t&&this.requestRender?.()}onScreen(e){return bp(this.registry.get(e)?.descriptor)}anchorPoint(t,n,r){return this.onScreen(t)?Cp(n,r):{x:e.O(n.time,r),y:e.T(n.price,r)}}snapToOHLC(e,t,n,r){let i=this.activeMagnet(),a=i===`none`?[]:this.displayDataGetter?.()??this.dataGetter?.()??[];if(r!==void 0){let o=this.panes?.valuesAt;return im(e,t,i,a,e=>o?.(r,e)??[],n)}return rm(e,t,i,a,n)}dragEdit(t,n){if(!(this.registry.get(t.type)?.descriptor.creation===`freehand`||this.onScreen(t.type)))return{handleAt:(t,r,i)=>{let a=cm(r.type)&&r.anchors.length>=2&&i<r.anchors.length?r.anchors[i===0?1:i-1]:void 0;return this.mods.shift&&a?dm(a,t,n):this.snapToOHLC(e.j(t.x,n),e.M(t.y,n),n,r.paneId)},snap:e=>this.snapToOHLC(e.time,e.price,n,t.paneId)}}undo(){if(!this.undoRedo)return!1;let e=this.undoRedo.undo();return e?(this.applyUndoAction(e),!0):!1}redo(){if(!this.undoRedo)return!1;let e=this.undoRedo.redo();return e?(this.applyRedoAction(e),!0):!1}foreignHistory=null;setForeignHistory(e){this.foreignHistory=e}applyUndoAction(e){if(Em(e)){this.foreignHistory?.(e,`undo`);return}if(e.type===`drawingBatch`&&Dm(e)){for(let t of[...e.actions??[]].reverse())this.applyUndoAction(t);return}this.applyHistory(Jp(this.drawings,e))}applyRedoAction(e){if(Em(e)){this.foreignHistory?.(e,`redo`);return}if(e.type===`drawingBatch`&&Dm(e)){for(let t of e.actions??[])this.applyRedoAction(t);return}this.applyHistory(Yp(this.drawings,e))}applyHistory(e){let t=new Map(this.drawings.map((e,t)=>[e.id,{d:e,index:t}]));this.drawings=e,this.settleAfterHistory();let n=new Set(e.map(e=>e.id));for(let e of t.keys())n.has(e)||(this.edits.delete(e),this.eventCallback?.(`drawingRemove`,{id:e}));e.forEach((e,n)=>{let r=t.get(e.id);r?(r.d!==e||r.index!==n)&&this.eventCallback?.(`drawingUpdate`,{id:e.id}):this.eventCallback?.(`drawingCreate`,{id:e.id,type:e.type,drawing:e})})}settleAfterHistory(){this.dropCopyGesture(),this.selection.clear(),this.creator.reset(),this.state=this.activeTool?`creating`:`idle`,this.requestRender?.()}record(e){this.batch?this.batch.push(e):this.undoRedo?.push(e)}batchUndo(e){if(this.batch){e();return}let t=[];this.batch=t;try{e()}finally{this.batch=null}t.length===1?this.undoRedo?.push(t[0]):t.length>1&&this.undoRedo?.push({type:`drawingBatch`,before:null,after:null,actions:t})}deselect(e){this.selection.remove(e)&&!this.selection.primary&&this.state===`selected`&&(this.state=`idle`)}addToSelection(e){this.selection.add(e),this.state=`selected`}groupMates(e){let t=e.group?.id;return t?this.drawings.filter(n=>n.group?.id===t&&n.id!==e.id&&this.shown(n)).map(e=>e.id):[]}select(e){if(this.state===`creating`)return!1;let t=this.drawings.find(t=>t.id===e);return!t||!this.shown(t)?!1:(this.selection.has(e)||this.selection.only(e,this.groupMates(t)),this.state=`selected`,this.requestRender?.(),!0)}setSelectionListener(e){this.selection.setListener(e)}getSelectedDrawingIds(){return this.selection.ids()}selectInRect(e,t,n){if(this.state===`creating`)return 0;let r=this.viewportFor(n,t);if(!r)return 0;this.selection.clear(),this.state=`idle`;let i=Math.min(e.x0,e.x1),a=Math.max(e.x0,e.x1),o=Math.min(e.y0,e.y1),s=Math.max(e.y0,e.y1);for(let e of this.drawings)!this.shown(e)||e.paneId!==n||e.anchors.some(t=>{let{x:n,y:c}=this.anchorPoint(e.type,t,r);return n>=i&&n<=a&&c>=o&&c<=s})&&this.addToSelection(e.id);return this.requestRender?.(),this.getSelectedDrawingIds().length}toggleSelectionAt(e,t){if(this.state===`creating`)return!1;let n=this.scopeAt(e,t);if(!n)return!1;for(let t=this.drawings.length-1;t>=0;t--){let r=this.drawings[t];if(!(!this.shown(r)||r.paneId!==n.pane)&&this.registry.get(r.type)?.hitTest(e,r,n.viewport,8))return this.selection.has(r.id)?this.deselect([r.id]):this.addToSelection(r.id),this.requestRender?.(),!0}return!1}beginMove(e,t){this.state=`moving`;let n=this.getSelectedDrawingIds().filter(e=>e!==t.id).map(e=>this.drawings.find(t=>t.id===e)).filter(e=>e!==void 0&&!e.locked&&e.paneId===t.paneId);this.drag.beginMove(e,[t,...n])}setFlags(e,t){this.batchUndo(()=>{for(let n of e){if((t.visible===void 0||n.visible===t.visible)&&(t.locked===void 0||n.locked===t.locked))continue;let e=Y(n);Object.assign(n,t),this.record({type:`drawingModify`,before:e,after:Y(n)})}}),t.visible===!1&&this.deselect(e.map(e=>e.id)),this.requestRender?.()}lockAllDrawings(){this.setFlags(this.drawings,{locked:!0})}unlockAllDrawings(){this.setFlags(this.drawings,{locked:!1})}hideAllDrawings(){this.setFlags(this.drawings,{visible:!1})}showAllDrawings(){this.setFlags(this.drawings,{visible:!0})}setTimeframe(e){e!==this.timeframe&&(this.timeframe=e,this.deselect(this.drawings.filter(e=>!this.shown(e)).map(e=>e.id)),this.requestRender?.())}isShown(e){let t=this.drawings.find(t=>t.id===e);return t!==void 0&&this.shown(t)}onDrawnPane(e){return e.paneId===void 0||(this.panes?.viewportOf(e.paneId)??null)!==null}shown(e){return e.visible&&Oa(e.intervals,this.timeframe)&&this.onDrawnPane(e)}setDrawingVisible(e,t){let n=this.drawings.find(t=>t.id===e);return n?(this.setFlags([n],{visible:t}),t):null}setDrawingsVisible(e,t){let n=new Set(e);this.setFlags(this.drawings.filter(e=>n.has(e.id)),{visible:t})}setDrawingsLocked(e,t){let n=new Set(e);this.setFlags(this.drawings.filter(e=>n.has(e.id)),{locked:t})}setDrawingLocked(e,t){let n=this.drawings.find(t=>t.id===e);return n?(this.setFlags([n],{locked:t}),t):null}setActiveTool(e){e&&this.setEraser(!1),this.clearHover(),this.dropCopyGesture();let t=e!==this.activeTool;this.activeTool=e,this.state=e?`creating`:`idle`,this.creator.reset(),t&&this.eventCallback?.(`drawingToolChange`,{tool:e})}setStayInDrawingMode(e){this.stayInDrawingMode=e}isStayInDrawingMode(){return this.stayInDrawingMode}setToolFilter(e){this.toolAllowed=e}copySelection(){let e=this.getSelectedDrawingIds().map(e=>this.drawings.find(t=>t.id===e)).filter(e=>e!==void 0);return e.length===0?0:(ym.drawings=e.map(e=>structuredClone(e)),ym.pastes=0,e.length)}canPaste(){return this.state!==`creating`&&ym.drawings.some(e=>this.canPasteType(e.type))}canPasteType(e){return this.registry.has(e)&&this.toolAllowed(e)}paste(){if(ym.drawings.length===0||this.state===`creating`)return[];let e=ym.drawings.every(e=>this.drawings.some(t=>t.id===e.id));ym.pastes+=1;let t=e?this.computeBarOffsetTime(3*ym.pastes):0,n=[];if(this.batchUndo(()=>{for(let e of ym.drawings)this.canPasteType(e.type)&&(e.paneId!==void 0&&(!this.panes?.hasPane(e.paneId)||this.registry.get(e.type)?.descriptor.priceOnly)||n.push(this.addDrawing({...e.paneId===void 0?{}:{paneId:e.paneId},type:e.type,anchors:this.onScreen(e.type)?Dp(e.anchors,wm*ym.pastes):e.anchors.map(e=>({...e,time:e.time+t})),style:{...e.style},options:e.options?Fp(e.options):void 0,intervals:e.intervals,meta:e.meta?structuredClone(e.meta):void 0,name:e.name})))}),n.length===0)return n;this.selection.clear(),this.state=`idle`;for(let e of n)this.isShown(e)&&this.addToSelection(e);return this.requestRender?.(),n}getActiveTool(){return this.activeTool}setStyle(e){Object.assign(this.activeStyle,e)}getActiveStyle(){return{...this.activeStyle}}setSelectedDrawingStyle(e,t){let n=t?[t]:this.getSelectedDrawingIds(),r=!1;return this.batchUndo(()=>{for(let t of n){let n=this.drawings.find(e=>e.id===t);if(!n||n.locked)continue;let i=Y(n);n.style={...n.style,...e},this.record({type:`drawingModify`,before:i,after:Y(n)}),r=!0}}),r&&this.requestRender?.(),r}onPointerDown(e,t,n=xm){if(this.eraser){let r=this.scopeAt(e,t);return r?this.erase(e,r,n.line):!1}return this.state===`creating`&&this.activeTool?this.handleCreationClick(e,t):this.state===`idle`||this.state===`selected`?this.handleSelectionClick(e,t,n):!1}placeAt(e,t){let n=this.state===`creating`?this.creator.current:null;return!n||n.anchors.length!==1||this.registry.get(n.type)?.descriptor.creation===`freehand`?!1:this.handleCreationClick(e,t)}takeBackPoint(){return this.state!==`creating`||!this.creator.current?!1:(this.creator.undoPoint(),this.requestRender?.(),!0)}onPointerMove(e,t){let n=this.state===`creating`?this.creator.current:null,r=n?this.viewportFor(n.paneId,t):null;if(n&&r&&this.creator.move(this.creationAnchor(n.type,e,r,n.paneId),e))return this.requestRender?.(),!0;if(this.pendingCopy){let{pos:t}=this.pendingCopy;if(Math.hypot(e.x-t.x,e.y-t.y)<Sm)return!0;this.startCopy()}if((this.state===`moving`||this.state===`resizing`)&&this.drag.isActive()){let n=this.drawings.find(e=>e.id===this.selection.primary),r=this.viewportFor(n?.paneId,t),i=n&&r?this.dragEdit(n,r):void 0;return!r||!this.drag.move(e,r,n&&this.registry.get(n.type),i)?!1:(this.requestRender?.(),!0)}return!1}onPointerUp(){let e=this.state===`creating`?this.creator.release():null;if(e)return this.afterCreationStep(e),!0;if(this.pendingCopy)return this.toggleCopied();if(this.copies)return this.endCopy(),!0;if(this.state===`moving`||this.state===`resizing`){let e=this.drag.end();return this.batchUndo(()=>{for(let{before:t,drawing:n}of e)Lp(n.anchors,t.anchors)&&Ip(n.options,t.options)||this.record({type:`drawingModify`,before:t,after:Y(n)})}),this.state=`selected`,this.requestRender?.(),!0}return!1}beginCopyDrag(e,t,n=xm){if(this.state===`creating`||this.state===`moving`||this.state===`resizing`||this.eraser)return!1;if(this.beginHandleDrag(e,t,n))return!0;let r=this.drawingAt(e,t,n.line);return r?(this.pendingCopy={pos:e,id:r},!0):!1}beginHandleDrag(e,t,n){let r=this.scopeAt(e,t),i=this.drawings.find(e=>e.id===this.selection.primary);if(!r||!i||i.locked||!this.shown(i)||i.paneId!==r.pane)return!1;let a=this.registry.get(i.type)?.hitTestAnchor(e,i,r.viewport,n.handle)??-1;return a<0?!1:(this.state=`resizing`,this.drag.beginResize(e,i,a),!0)}dropCopyGesture(){this.pendingCopy=null;let e=this.copies;e&&(this.copies=null,this.copySources=new Map,this.drag.end(),this.drawings=this.drawings.filter(t=>!e.includes(t.id)),this.deselect(e),this.state===`moving`&&(this.state=`idle`))}startCopy(){let{pos:e,id:t}=this.pendingCopy;this.pendingCopy=null;let n=this.selection.has(t)?[t,...this.getSelectedDrawingIds().filter(e=>e!==t)]:[t],r=this.drawings.find(e=>e.id===t),i=n.map(e=>this.drawings.find(t=>t.id===e)).filter(e=>e!==void 0&&this.shown(e)&&e.paneId===r?.paneId&&this.canPasteType(e.type));if(i.length===0)return;let a=i.map(e=>{let{group:t,...n}=structuredClone(e);return{...n,id:Hp(),locked:!1}});this.copySources=new Map(a.map((e,t)=>[e.id,i[t].anchors.map(e=>({...e}))])),this.drawings=[...this.drawings,...a],this.copies=a.map(e=>e.id),this.copiedFrom=this.getSelectedDrawingIds(),this.selection.only(a[0].id,this.copies.slice(1)),this.beginMove(e,a[0]),this.requestRender?.()}endCopy(){let e=this.copies;this.copies=null,this.drag.end(),this.state=`selected`;let t=this.copySources;this.copySources=new Map;let n=e.map(e=>this.drawings.find(t=>t.id===e)).filter(e=>e!==void 0);if(n.every(e=>{let n=t.get(e.id);return!!n&&Lp(e.anchors,n)})){this.drawings=this.drawings.filter(t=>!e.includes(t.id)),this.deselect(e),this.requestRender?.();return}this.batchUndo(()=>{for(let e of n)this.record({type:`drawingCreate`,before:null,after:Y(e)})});for(let e of n)this.eventCallback?.(`drawingCreate`,{id:e.id,type:e.type,drawing:e});this.requestRender?.()}toggleCopied(){let{id:e}=this.pendingCopy;return this.pendingCopy=null,this.selection.has(e)?this.deselect([e]):this.addToSelection(e),this.requestRender?.(),!0}nudge(e,t,n){if(this.state!==`selected`)return!1;let r=this.getSelectedDrawingIds().map(e=>this.drawings.find(t=>t.id===e)).filter(e=>e!==void 0&&!e.locked&&this.shown(e));if(r.length===0||e===0&&t===0)return!1;let i=r.map(e=>e.id).join(`,`),a=Date.now(),o=this.lastNudge,s=o&&o.key===i&&a-o.at<Cm&&o.action!==null&&this.undoRedo?.last()===o.action?o:null,c=s?s.before:r.map(Y),l=r.filter(r=>{let i=this.viewportFor(r.paneId,n);return i?(r.anchors=this.onScreen(r.type)?Ep(r.anchors,e*(i.barWidth+i.barSpacing),t,i):gm(r.anchors,e,t,i),!0):!1});if(l.length===0)return!1;s&&this.undoRedo?.dropLast(),this.batchUndo(()=>{for(let e of l){let t=c.find(t=>t.id===e.id);t&&this.record({type:`drawingModify`,before:t,after:Y(e)})}}),this.lastNudge={key:i,at:a,before:c,action:this.undoRedo?.last()??null};for(let e of l)this.eventCallback?.(`drawingUpdate`,{id:e.id});return this.requestRender?.(),!0}onKeyDown(e,t=!1,n){let r=Zp(e,t,n);if(!r)return!1;let i=this.state===`selected`?this.selection.primary:null;switch(r){case`copy`:return i!==null&&this.copySelection()>0;case`paste`:return this.paste().length>0;case`duplicate`:return i!==null&&this.duplicateDrawing(i)!==null;case`group`:return i!==null&&this.groupDrawings(this.getSelectedDrawingIds())!==null;case`ungroup`:return this.ungroupSelection();case`front`:case`forward`:case`backward`:case`back`:return i!==null&&this.moveDrawing(i,r);case`undo`:return this.state===`creating`&&this.creator.current?(this.creator.undoPoint(),this.requestRender?.(),!0):this.undo();case`redo`:return this.redo();case`escape`:return this.escape();case`delete`:return i!==null&&this.removeDrawings(this.getSelectedDrawingIds())>0;case`finish`:{if(this.state!==`creating`||!this.creator.current)return!1;let e=this.creator.finish();return e===`done`?(this.afterCreationStep(e),!0):!1}}}escape(){if(this.pendingCopy||this.copies){let e=this.copies?this.copiedFrom.filter(e=>this.isShown(e)):[];return this.dropCopyGesture(),e.length>0&&(this.selection.only(e[0],e.slice(1)),this.state=`selected`),this.requestRender?.(),!0}if(this.state===`moving`||this.state===`resizing`){let e=new Map(this.drag.end().map(({before:e})=>[e.id,Y(e)]));return this.drawings=this.drawings.map(t=>e.get(t.id)??t),this.state=`selected`,this.requestRender?.(),!0}return this.eraser?(this.setEraser(!1),!0):this.state===`creating`?(this.setActiveTool(null),this.requestRender?.(),!0):this.state===`selected`?(this.selection.clear(),this.state=`idle`,this.requestRender?.(),!0):!1}ungroupSelection(){let e=new Set;for(let t of this.getSelectedDrawingIds()){let n=this.drawings.find(e=>e.id===t)?.group;n&&e.add(n.id)}for(let t of e)this.ungroup(t);return e.size>0}getDrawings(){return this.drawings}setDrawings(e){this.dropCopyGesture(),Wp(e),this.drawings=this.upgradeLegacyAnchors(e).map(e=>{let n=e.name===void 0||e.name===Pp(e.name)?e:Pm(e,Pp(e.name)),r=this.onScreen(n.type)?{...n,anchors:wp(n.anchors)}:n;if(!r.options&&r.intervals===void 0)return r;let i=(0,t.sanitizeDrawingOptions)(this.optionDefs(r.type),r.options);return{...r,options:Object.keys(i).length>0?i:void 0,intervals:ka(r.intervals)??void 0}});let n=new Map(this.drawings.map(e=>[e.id,e]));this.deselect(this.getSelectedDrawingIds().filter(e=>{let t=n.get(e);return!t||!this.shown(t)}));let r=new Set(n.keys());for(let e of[...this.edits.keys()])r.has(e)||this.edits.delete(e);this.requestRender?.()}moveDrawing(e,t){let n=this.drawings.findIndex(t=>t.id===e);if(n<0)return!1;let r=Kp(n,this.drawings.length,t);if(r===n)return!1;let i=this.drawings.map(e=>e.id),a=[...this.drawings],[o]=a.splice(n,1);return a.splice(r,0,o),this.drawings=a,this.record({type:`drawingOrder`,before:null,after:null,order:{before:i,after:a.map(e=>e.id)}}),this.eventCallback?.(`drawingUpdate`,{id:e}),this.requestRender?.(),!0}getGroups(){let e=new Map;for(let t of this.drawings){if(!t.group)continue;let n=e.get(t.group.id)??{id:t.group.id,name:t.group.name,ids:[]};n.ids.push(t.id),e.set(t.group.id,n)}return[...e.values()]}updateGroup(e,t){let n=this.drawings.filter(t=>t.group?.id===e);return n.length===0?!1:(this.batchUndo(()=>{for(let e of n){let n=Y(e);t(e),this.record({type:`drawingModify`,before:n,after:Y(e)}),this.eventCallback?.(`drawingUpdate`,{id:e.id})}}),this.requestRender?.(),!0)}groupDrawings(e,t){let n=new Set(e),r=this.drawings.filter(e=>n.has(e.id));if(r.length<2)return null;let{id:i,number:a}=Up(),o={id:i,name:Fm(t)||`Group ${a}`};return this.batchUndo(()=>{for(let e of r){let t=Y(e);e.group={...o},this.record({type:`drawingModify`,before:t,after:Y(e)}),this.eventCallback?.(`drawingUpdate`,{id:e.id})}}),this.requestRender?.(),o.id}ungroup(e){return this.updateGroup(e,e=>{delete e.group})}renameGroup(e,t){let n=Fm(t);return n.length>0&&this.updateGroup(e,t=>{t.group={id:e,name:n}})}setGroupVisible(e,t){let n=this.updateGroup(e,e=>{e.visible=t});return n&&!t&&this.deselect(this.drawings.filter(t=>t.group?.id===e).map(e=>e.id)),n}setGroupLocked(e,t){return this.updateGroup(e,e=>{e.locked=t})}priceAt(e,t,n){let r=this.drawings.find(t=>t.id===e);if(!r)return null;let i=this.registry.get(r.type)?.priceAt?.(r,t,n)??null;return i&&i.every(Number.isFinite)?i:null}hasPriceLevels(e){let t=this.drawings.find(t=>t.id===e);return!!t&&typeof this.registry.get(t.type)?.priceAt==`function`}getPlugin(e){return this.registry.get(e)??null}textBoxOf(e,t){let n=this.drawings.find(t=>t.id===e),r=n?this.viewportFor(n.paneId,t):null;return!n||!r?null:this.registry.get(n.type)?.textBox?.(n,r)??null}getDescriptor(e){return this.registry.get(e)?.descriptor??null}getOptionDefs(e){return this.optionDefs(e)??{}}optionDefs(e){return this.registry.get(e)?.descriptor.options}initialOptions(e,n){let r=this.optionDefs(e),i={...Fp(this.toolDefaults.get(e)??{}),...(0,t.sanitizeDrawingOptions)(r,n)};return Object.keys(i).length>0?i:void 0}setToolDefaults(e,n){let r=n?(0,t.sanitizeDrawingOptions)(this.optionDefs(e),n):{};Object.keys(r).length>0?this.toolDefaults.set(e,r):this.toolDefaults.delete(e)}getToolDefaults(e){return Fp(this.toolDefaults.get(e)??{})}getDrawingOptions(e){let n=this.drawings.find(t=>t.id===e);return n?(0,t.resolveDrawingOptions)(this.optionDefs(n.type),n.options):{}}setDrawingOptions(e,t){return this.updateDrawing(e,{options:t})}updateDrawing(e,n){let r=this.drawings.find(t=>t.id===e);if(!r||n.anchors&&!(n.anchors.length===r.anchors.length&&n.anchors.every(e=>Number.isFinite(e.time)&&Number.isFinite(e.price))))return!1;let i=this.edits.has(e)?null:Y(r);if(n.anchors&&(r.anchors=this.onScreen(r.type)?wp(n.anchors):n.anchors.map(e=>({time:e.time,price:e.price}))),n.style&&(r.style={...r.style,...n.style}),n.options){let e={...r.options,...(0,t.sanitizeDrawingOptions)(this.optionDefs(r.type),n.options)};r.options=Object.keys(e).length>0?e:void 0}if(n.name!==void 0){let e=Pp(n.name);e===void 0?delete r.name:r.name=e}return n.intervals!==void 0&&(r.intervals=ka(n.intervals)??void 0,!this.edits.has(e)&&!this.shown(r)&&this.deselect([e])),i&&this.record({type:`drawingModify`,before:i,after:Y(r)}),this.eventCallback?.(`drawingUpdate`,{id:e}),this.requestRender?.(),!0}beginEdit(e){let t=this.drawings.find(t=>t.id===e);return t?(this.edits.has(e)||this.edits.set(e,Y(t)),!0):!1}endEdit(e,{cancel:t=!1}={}){let n=this.edits.get(e);if(!n)return;this.edits.delete(e);let r=this.drawings.findIndex(t=>t.id===e);r<0||(t?(this.drawings[r]=n,this.requestRender?.()):JSON.stringify(n)!==JSON.stringify(this.drawings[r])&&this.record({type:`drawingModify`,before:n,after:Y(this.drawings[r])}),this.shown(this.drawings[r])||this.deselect([e]),this.eventCallback?.(`drawingUpdate`,{id:e}))}addDrawing(e){e.id&&Wp([{id:e.id}]);let t=e.id??Hp(),n={id:t,type:e.type,anchors:this.onScreen(e.type)?wp(e.anchors):e.anchors.map(e=>({...e})),style:{...this.activeStyle,...e.style},visible:e.visible??!0,locked:e.locked??!1,options:this.initialOptions(e.type,e.options),intervals:ka(e.intervals)??void 0,meta:e.meta,...typeof e.paneId==`string`?{paneId:e.paneId}:{}},r=Pp(e.name);return r!==void 0&&(n.name=r),this.drawings=[...this.drawings,n],this.record({type:`drawingCreate`,before:null,after:Y(n)}),this.eventCallback?.(`drawingCreate`,{id:t,type:n.type,drawing:n}),this.requestRender?.(),t}upgradeLegacyAnchors(e){let t=this.dataGetter?.();if(!t||t.length===0)return e;let n=bm;return t[t.length-1].time<n?e:e.map(e=>this.onScreen(e.type)?e:{...e,anchors:e.anchors.map(e=>{if(!Number.isFinite(e.time)||e.time<0||e.time>=n)return e;let r=Math.max(0,Math.min(t.length-1,Math.round(e.time)));return{...e,time:t[r].time}})})}removeDrawing(e){this.hoverDrawing===e&&this.clearHover();let t=this.drawings.findIndex(t=>t.id===e),n=this.drawings[t];this.drawings=this.drawings.filter(t=>t.id!==e),n&&this.record({type:`drawingRemove`,before:structuredClone(n),after:null,index:t}),this.deselect([e]),this.edits.delete(e),this.eventCallback?.(`drawingRemove`,{id:e}),this.requestRender?.()}removeDrawings(e){let t=[...new Set(e)].filter(e=>{let t=this.drawings.find(t=>t.id===e);return t!==void 0&&!t.locked});return t.length===0?0:(this.batchUndo(()=>{for(let e of t)this.removeDrawing(e)}),t.length)}amendNew(e,t){let n=this.drawings.find(t=>t.id===e);if(!n)return!1;let r=this.undoRedo?.last();if(!this.undoRedo||r?.type!==`drawingCreate`||r.after?.id!==e)return this.updateDrawing(e,t);let i=[],a=this.batch;this.batch=i;let o=!1;try{o=this.updateDrawing(e,t)}finally{this.batch=a}return o?(this.undoRedo.replaceLast({...r,after:Y(n)}),!0):!1}takeBack(e){let t=this.undoRedo?.last();if(!this.undoRedo||t?.type!==`drawingCreate`||t.after?.id!==e){this.removeDrawing(e);return}this.undoRedo.dropLast(),this.drawings=this.drawings.filter(t=>t.id!==e),this.deselect([e]),this.edits.delete(e),this.eventCallback?.(`drawingRemove`,{id:e}),this.requestRender?.()}duplicateDrawing(e){let t=this.drawings.find(t=>t.id===e);if(!t)return null;let n=structuredClone(t);n.id=Hp();let r=this.computeBarOffsetTime(3);return n.anchors=this.onScreen(n.type)?Dp(n.anchors,wm):n.anchors.map(e=>({...e,time:e.time+r})),n.locked=!1,this.drawings.push(n),this.record({type:`drawingCreate`,before:null,after:structuredClone(n)}),this.selection.only(n.id),this.state=`selected`,this.eventCallback?.(`drawingCreate`,{id:n.id,type:n.type,drawing:n}),this.requestRender?.(),n.id}clearDrawings(){this.dropCopyGesture(),this.drawings=[],this.selection.clear(),this.state=`idle`,this.requestRender?.()}getSelectedDrawingId(){return this.selection.primary}render(t,n){t.save(),t.textAlign=`left`,t.textBaseline=`alphabetic`;let r=this.selection.primary,i=this.state===`resizing`&&r?this.drag.activeHandle():-1;gp({primary:r,hover:this.hoverHandle,drag:i>=0&&r?{id:r,index:i}:null});let a=new Map;this.extents=a;try{for(let e of this.drawings){if(!this.shown(e))continue;let r=this.registry.get(e.type),i=this.viewportFor(e.paneId,n);if(!r||!i)continue;mn();let o=null;try{Nm(t,r,e,i,this.selection.has(e.id))}finally{o=gn()}o&&a.set(e.id,o)}let r=this.creator.previewState(),i=r?this.registry.get(r.type):void 0,o=r?this.viewportFor(r.paneId,n):null;if(r&&i&&o&&(gp({primary:r.id,hover:null,drag:null}),Nm(t,i,r,o,!0),r.anchors.length<2)){let n=o;yp(t,r,r.anchors.map(t=>this.onScreen(r.type)?Cp(t,n):{x:e.O(t.time,n),y:e.T(t.price,n)}))}}finally{gp(null)}t.restore()}computeBarOffsetTime(e){let t=this.dataGetter?.();if(!t||t.length<2)return e;let n=Math.max(0,t.length-20),r=[];for(let e=n+1;e<t.length;e++)r.push(t[e].time-t[e-1].time);return r.length===0?e:(r.sort((e,t)=>e-t),e*r[Math.floor(r.length/2)])}creationAnchor(t,n,r,i){if(this.onScreen(t))return Tp(n,r);let a=e.j(n.x,r),o=e.M(n.y,r);if(this.registry.get(t)?.descriptor.creation===`freehand`)return{time:a,price:o};let s=this.creator.current?.anchors,c=s&&s.length>0?s[s.length-1]:void 0;return this.mods.shift&&c&&cm(t)?dm(c,n,r):this.snapToOHLC(a,o,r,i)}handleCreationClick(e,t){let n=this.activeTool,r=n?this.registry.get(n):void 0;if(!n||!r)return!1;let i=this.creator.current,a=i?i.paneId:this.paneAt(e);if(a===null||a!==void 0&&r.descriptor.priceOnly)return!1;let o=this.viewportFor(a,t);if(!o)return!1;let s=()=>({id:Hp(),type:n,anchors:[],style:{...this.activeStyle},visible:!0,locked:!1,options:this.initialOptions(n),...a===void 0?{}:{paneId:a}});return this.creationPressAt=Date.now(),this.afterCreationStep(this.creator.press(r,s,this.creationAnchor(n,e,o,a),e,e=>this.anchorPoint(n,e,o))),!0}afterCreationStep(e){e===`done`?this.finalizeCreation():e===`cancel`&&this.creator.reset(),this.requestRender?.()}setEraser(e){e!==this.eraser&&(this.eraser=e,this.clearHover(),e&&(this.setActiveTool(null),this.selection.clear(),this.state=`idle`),this.eventCallback?.(`toolModeChange`,{eraser:e}),this.requestRender?.())}isEraser(){return this.eraser}erase(e,t,n){let r=this.erasableAt(e,t,n);return r?(this.removeDrawing(r),!0):!1}erasableAt(e,t,n=xm.line){for(let r=this.drawings.length-1;r>=0;r--){let i=this.drawings[r];if(!(!this.shown(i)||i.locked||i.paneId!==t.pane)&&this.registry.get(i.type)?.hitTest(e,i,t.viewport,n))return i.id}return null}justFinished(e=500){return Date.now()-this.creationPressAt<e&&this.finishedAt>=this.creationPressAt}finalizeCreation(){let e=this.creator.take();if(e){if(this.finishedAt=Date.now(),this.drawings.push(e),this.selection.only(e.id),this.record({type:`drawingCreate`,before:null,after:structuredClone(e)}),this.eventCallback?.(`drawingCreate`,{id:e.id,type:e.type,drawing:e,drawn:!0}),this.stayInDrawingMode&&this.activeTool){this.selection.clear(),this.state=`creating`;return}this.activeTool=null,this.state=`selected`,this.eventCallback?.(`drawingToolChange`,{tool:null})}}isDragging(){return this.state===`moving`||this.state===`resizing`}drawingAt(e,t,n=xm.line){let r=this.scopeAt(e,t);if(!r)return null;for(let t=this.drawings.length-1;t>=0;t--){let i=this.drawings[t];if(!(!this.shown(i)||i.paneId!==r.pane)&&this.registry.get(i.type)?.hitTest(e,i,r.viewport,n))return i.id}return null}hoverCursorAt(e,t){let n=this.hoverAt(e,t),r=n.handle?.id!==this.hoverHandle?.id||n.handle?.index!==this.hoverHandle?.index;return this.hoverHandle=n.handle,this.hoverDrawing=n.drawing,r&&this.requestRender?.(),n.cursor}drawnExtent(e){return this.extents.get(e)??null}clearHover(){let e=this.hoverHandle;this.hoverHandle=null,this.hoverDrawing=null,e&&this.requestRender?.()}renderHover(e,t){let n=this.hoverDrawing;if(!n||this.selection.has(n)&&!this.eraser||this.activeTool||this.state===`creating`)return;let r=this.drawings.find(e=>e.id===n);if(!r||r.locked||!this.shown(r))return;let i=this.registry.get(r.type),a=this.viewportFor(r.paneId,t);i&&a&&Nm(e,i,r,a,!1,!0)}axisSpans(e){let t=this.creator.previewState(),n=t??(this.selection.primary?this.drawings.find(e=>e.id===this.selection.primary):void 0);if(!n||!t&&!this.shown(n))return[];let r=this.registry.get(n.type),i=this.viewportFor(n.paneId,e),a=r&&i?vm(n,r.descriptor):null;return a&&i?[{...a,color:n.style.color,viewport:i}]:[]}hoverAt(e,t){let n={cursor:null,handle:null,drawing:null},r=this.scopeAt(e,t);if(!r)return n;if(this.eraser){let t=this.erasableAt(e,r);return{...n,cursor:t?`pointer`:null,drawing:t}}if(this.activeTool||this.state===`creating`)return n;let i=xm.handle,a=r.viewport;if(this.selection.primary){let t=this.drawings.find(e=>e.id===this.selection.primary),n=t&&this.shown(t)&&!t.locked&&t.paneId===r.pane?this.registry.get(t.type):void 0,o=t&&n?n.hitTestAnchor(e,t,a,i):-1;if(t&&o>=0)return{cursor:`move`,handle:{id:t.id,index:o},drawing:t.id}}for(let t=this.drawings.length-1;t>=0;t--){let n=this.drawings[t];if(!(!this.shown(n)||n.locked||n.paneId!==r.pane)&&this.registry.get(n.type)?.hitTest(e,n,a,xm.line))return{cursor:`pointer`,handle:null,drawing:n.id}}return n}handleSelectionClick(e,t,n){let r=n.line,i=this.scopeAt(e,t);if(!i)return!1;let a=i.viewport;if(this.selection.primary){let t=this.drawings.find(e=>e.id===this.selection.primary);if(t&&this.shown(t)&&!t.locked&&t.paneId===i.pane){let i=this.registry.get(t.type);if(i){let o=i.hitTestAnchor(e,t,a,n.handle);if(o>=0)return this.state=`resizing`,this.drag.beginResize(e,t,o),!0;if(i.hitTest(e,t,a,r))return this.beginMove(e,t),!0}}}for(let t=this.drawings.length-1;t>=0;t--){let n=this.drawings[t];if(!this.shown(n)||n.paneId!==i.pane)continue;let o=this.registry.get(n.type);if(o&&o.hitTest(e,n,a,r))return this.selection.has(n.id)?this.selection.focus(n.id):this.selection.only(n.id,this.groupMates(n)),this.requestRender?.(),n.locked?(this.state=`selected`,!1):(this.beginMove(e,n),!0)}return this.selection.primary&&(this.selection.clear(),this.state=`idle`,this.requestRender?.()),!1}},km=.55,Am=6,jm=[`fill`,`fillRect`,`fillText`,`strokeText`];function Mm(e,n){e.shadowColor=(0,t.withAlpha)(n,km),e.shadowBlur=Am;let r=e;for(let e of jm)r[e]=()=>void 0;return()=>{for(let e of jm)delete r[e]}}function Nm(e,t,n,r,i,a=!1){let o=r.chartRect;e.save(),e.beginPath(),e.rect(o.x,o.y,o.width,o.height),e.clip(),vn(o);let s=a?Mm(e,n.style.color):null;try{t.render(e,n,r,i)}finally{s?.(),vn(null),e.restore()}}function Pm(e,t){let{name:n,...r}=e;return t===void 0?r:{...r,name:t}}function Fm(e){return(e??``).trim().slice(0,80)}var Im=class{keepOut=null;formatTime=null;constructor(e){this.manager=e}setKeepOut(e){this.keepOut=e}setTimeFormat(e){this.formatTime=e}getKeepOut(){return this.keepOut?.()??[]}renderHover(e,t,n){zn(n??null);try{this.manager.renderHover(e,t)}finally{zn(null)}}axisSpans(e){return this.manager.axisSpans(e)}render(e,t,n){zn(n??null),Jn(this.getKeepOut());try{this.manager.render(e,this.formatTime?{...t,formatTime:this.formatTime}:t)}finally{Jn(null),zn(null)}}};function Lm(e,t,n){let r=Math.max(0,t),i=Math.min(e.length-1,n);if(i<=r)return null;let a=r,o=r;for(let t=r;t<=i;t++)e[t].high>e[a].high&&(a=t),e[t].low<e[o].low&&(o=t);if(a===o)return null;let s={time:e[a].time,price:e[a].high},c={time:e[o].time,price:e[o].low};return a<o?[s,c]:[c,s]}var Rm={0:`#787b86`,.236:`#e8505b`,.25:`#e8505b`,.382:`#d97a0e`,.5:`#1a9a6a`,.618:`#0e93a3`,.75:`#2f7fd8`,.786:`#5b6cf0`,1:`#787b86`,1.272:`#b25ad1`,1.414:`#d6487f`,1.618:`#2f7fd8`,2:`#7a5cff`,2.618:`#e8505b`,3.618:`#b25ad1`,4.236:`#d6487f`};function zm(e,t=[]){return Bm(e,t).map(e=>{let t=Rm[e.value];return t?{...e,color:t}:e})}function Bm(e,t=[]){return[...e.map(e=>({value:e,visible:!0})),...t.map(e=>({value:e,visible:!1}))].sort((e,t)=>e.value-t.value)}function Vm(e=!1,t=!1){return{extendLeft:{kind:`boolean`,label:`Extend left`,default:e},extendRight:{kind:`boolean`,label:`Extend right`,default:t}}}var Hm={showPrice:{kind:`boolean`,label:`Show price`,default:!0}},Um={trendLine:{kind:`boolean`,label:`Trend line`,default:!0},oneColor:{kind:`boolean`,label:`Use one color`,default:!1}},Wm={showLevels:{kind:`boolean`,label:`Show levels`,default:!0},showPrices:{kind:`boolean`,label:`Show prices`,default:!0},labelPosition:{kind:`choice`,label:`Labels`,default:`left`,choices:[{value:`left`,label:`Left`},{value:`right`,label:`Right`}]}};function Gm(e,t){let n=e.textBackground??t.box,r=e.textBorder??t.border,i=!t.fill&&!e.fillColor?void 0:P(e);return{fontSize:Sn(e),color:e.textColor??kn(e.color),fill:n&&i?i:void 0,stroke:r?e.borderColor??e.color:void 0,maxWidth:e.textWrap===void 0?t.width:e.textWrap>0?e.textWrap:1/0,bold:e.bold,italic:e.italic,align:e.textAlign}}var Km=1.3,qm=12,Jm=3;function Ym(e,t=!1,n=!1,r=!0){let i=M();return`${n?`italic `:``}${t?`bold `:``}${e}px ${r?i.prose:i.figures}`}function Xm(e,t,n,r=qm){let i=[];for(let a of t.split(`
|
|
2
2
|
`)){let t=``;for(let r of a.split(/\s+/).filter(Boolean)){let a=t?`${t} ${r}`:r;if(e(a)<=n){t=a;continue}t&&i.push(t),t=e(r)<=n?r:Zm(e,r,n)}if(i.push(t),i.length>=r)break}return i.length>r&&(i.length=r),i}function Zm(e,t,n){if(e(t)<=n)return t;let r=1,i=t.length-1;for(;r<i;){let a=Math.ceil((r+i)/2);e(`${t.slice(0,a)}…`)<=n?r=a:i=a-1}return`${t.slice(0,r)}…`}var Qm=200,$m=new Map;function eh(e,t,n,r,i){let a=`${r}|${n}|${i}|${t}`,o=$m.get(a);if(o)return o;$m.size>=Qm&&$m.clear();let s=Xm(e,t,n,i);return $m.set(a,s),s}function th(e,t,n,r,i){return{x:n,y:r,width:Math.max(0,...t.map(e))+16,height:t.length*i*Km+12}}function nh(e,t,n){let r=Ym(n.fontSize,n.bold,n.italic);e.font=r;let i=t=>e.measureText(t).width,{width:a,height:o}=th(i,eh(i,t,n.maxWidth,r,n.maxLines??qm),0,0,n.fontSize);return{width:a,height:o}}function rh(e,t,n,r,i){let a=Ym(i.fontSize,i.bold,i.italic);e.font=a;let o=t=>e.measureText(t).width,s=eh(o,t,i.maxWidth,a,i.maxLines??qm),c=th(o,s,n,r,i.fontSize);if(i.fill||i.stroke){let t=Math.round(c.x)+.5,n=Math.round(c.y)+.5;e.beginPath(),i.traceBox?i.traceBox(e,t,n,Math.round(c.width)-1,Math.round(c.height)-1,Jm):typeof e.roundRect==`function`?e.roundRect(t,n,Math.round(c.width)-1,Math.round(c.height)-1,Jm):e.rect(t,n,Math.round(c.width)-1,Math.round(c.height)-1),i.fill&&(e.fillStyle=i.fill,e.fill()),i.stroke&&(e.strokeStyle=i.stroke,e.lineWidth=1,e.setLineDash([]),e.stroke())}e.fillStyle=i.color,e.textAlign=`left`,e.textBaseline=`top`;let l=c.width-16;return s.forEach((t,a)=>{let s=l-o(t),c=i.align===`center`?s/2:i.align===`right`?s:0,u=r+6+a*i.fontSize*Km;i.fill?e.fillText(t,n+8+c,u):F(e,t,n+8+c,u)}),c}var ih=3;function ah(e,t,n,r=!0){let i=Math.round(t.x-ih)+.5,a=Math.round(t.y-ih)+.5,o=Math.round(t.width+ih*2)-1,s=Math.round(t.height+ih*2)-1;hn(i-1,a-1,o+2,s+2),r&&(e.save(),e.strokeStyle=n,e.lineWidth=1,e.globalAlpha=1,e.setLineDash([]),e.beginPath(),typeof e.roundRect==`function`?e.roundRect(i,a,o,s,Jm+ih):e.rect(i,a,o,s),e.stroke(),e.restore())}function oh(e){let t=e.map(e=>e.x),n=e.map(e=>e.y),r=Math.min(...t),i=Math.min(...n);return{x:r,y:i,width:Math.max(...t)-r,height:Math.max(...n)-i}}function sh(e,t,n=0){return e.x>=t.x-n&&e.x<=t.x+t.width+n&&e.y>=t.y-n&&e.y<=t.y+t.height+n}var ch=1e3,lh=class{boxes=new Map;set(e,t){this.boxes.size>=ch&&!this.boxes.has(e)&&this.boxes.clear(),this.boxes.set(e,t)}get(e){return this.boxes.get(e)}},uh=4,dh=6,fh=1.3,ph=20,mh=.5,hh=1e-6;function gh(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=0,o=1,s=[[-r,e.x-n.x],[r,n.x+n.width-e.x],[-i,e.y-n.y],[i,n.y+n.height-e.y]];for(let[e,t]of s){if(e===0){if(t<0)return null;continue}let n=t/e;if(e<0?a=Math.max(a,n):o=Math.min(o,n),a>o)return null}return[{x:e.x+a*r,y:e.y+a*i},{x:e.x+o*r,y:e.y+o*i}]}var _h=1e4,vh=class{boxes=new Map;set(e,t){if(!t){this.boxes.delete(e);return}this.boxes.delete(e),this.boxes.size>=_h&&this.boxes.delete(this.boxes.keys().next().value),this.boxes.set(e,t)}bounds(e){let t=this.boxes.get(e);if(!t)return null;let n=Math.cos(t.angle),r=Math.sin(t.angle),i=[[t.left,t.top],[t.left+t.width,t.top],[t.left,t.top+t.height],[t.left+t.width,t.top+t.height]].map(([e,i])=>({x:t.x+e*n-i*r,y:t.y+e*r+i*n})),a=i.map(e=>e.x),o=i.map(e=>e.y),s=Math.min(...a),c=Math.min(...o);return{x:s,y:c,width:Math.max(...a)-s,height:Math.max(...o)-c}}hit(e,t,n){let r=this.boxes.get(e);if(!r)return!1;let i=t.x-r.x,a=t.y-r.y,o=Math.cos(r.angle),s=Math.sin(r.angle),c=i*o+a*s,l=-i*s+a*o;return c>=r.left-n&&c<=r.left+r.width+n&&l>=r.top-n&&l<=r.top+r.height+n}};function yh(e){let t=e.text?.trim();return t?t.split(`
|
|
3
3
|
`).slice(0,ph):[]}function bh(e,t){let n=Sn(t);return e.font=Ym(n,t.bold,t.italic),e.fillStyle=t.textColor??t.color,n*fh}function xh(e,t,n,r,i){let a=yh(t);if(a.length===0)return null;let o=i?gh(n,r,i):[n,r];if(!o)return null;let[s,c]=o,[l,u]=Math.abs(c.x-s.x)<mh?s.y>c.y?[s,c]:[c,s]:s.x<c.x?[s,c]:[c,s],d=Math.atan2(u.y-l.y,u.x-l.x),f=t.textAlign??`center`,p=f===`left`?l:f===`right`?u:{x:(l.x+u.x)/2,y:(l.y+u.y)/2},m=f===`left`?dh:f===`right`?-dh:0;e.save();let h=bh(e,t);e.translate(p.x,p.y),e.rotate(d),e.textAlign=f;let g=t.textVAlign??`top`;e.textBaseline=g===`top`?`bottom`:g===`bottom`?`top`:`middle`;let _=0;a.forEach((t,n)=>{_=Math.max(_,e.measureText(t).width);let r=g===`top`?-uh-(a.length-1-n)*h:g===`bottom`?uh+n*h:(n-(a.length-1)/2)*h;if(F(e,t,m,r),Math.abs(d)<hh){let n=e.measureText(t).width,i=p.x+m-(f===`left`?0:f===`right`?n:n/2),a=p.y+r-(g===`top`?h:g===`bottom`?0:h/2);Yn(i,a,i+n,a+h)}}),e.restore();let v=a.length*h;return{x:p.x,y:p.y,angle:d,left:m-(f===`left`?0:f===`right`?_:_/2),top:g===`top`?-uh-v:g===`bottom`?uh:-v/2,width:_,height:v}}function Sh(e,t,n){let r=yh(t);if(r.length===0)return null;e.save();let i=bh(e,t),a=t.textAlign??`center`,o=a===`left`?n.x+8:a===`right`?n.x+n.width-8:n.x+n.width/2,s=t.textVAlign??`top`,c=r.length*i,l=s===`top`?n.y+6:s===`bottom`?n.y+n.height-6-c:n.y+(n.height-c)/2;e.textAlign=a,e.textBaseline=`top`;let u=0;return r.forEach((t,n)=>{u=Math.max(u,e.measureText(t).width),F(e,t,o,l+n*i)}),e.restore(),{x:0,y:0,angle:0,left:a===`left`?o:a===`right`?o-u:o-u/2,top:l,width:u,height:c}}var Ch=28,wh=48;function Th(e,t){return Math.atan2(e.y-t.y,t.x-e.x)*180/Math.PI}var Eh=class extends J{descriptor={type:`trendAngle`,name:`Trend Angle`,requiredAnchors:2,text:!0};render(e,t,n,r){if(this.texts.set(t.id,null),t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Th(i,a),s=a.x>=i.x?1:-1;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e),this.applyGuideStyle(e,t.style.color,!0),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(i.x+s*wh,i.y),e.stroke(),e.setLineDash([]);let c=Math.atan2(a.y-i.y,a.x-i.x),l=s>0?0:Math.PI;s<0&&c<0&&(c+=2*Math.PI),e.beginPath(),e.arc(i.x,i.y,Ch,Math.min(l,c),Math.max(l,c)),e.stroke(),e.globalAlpha=1,e.font=N(`label`),e.fillStyle=kn(t.style.color),e.textAlign=s>0?`left`:`right`,e.textBaseline=`middle`,F(e,`${o.toFixed(1)}°`,i.x+s*(Ch+6),i.y+(o>=0?-8:8)),this.texts.set(t.id,xh(e,t.style,this.anchorToPixel(t.anchors[0],n),this.anchorToPixel(t.anchors[1],n),n.chartRect)),r&&this.renderAnchorHandles(e,t,n)}texts=new vh;textBox(e){return this.texts.bounds(e.id)}hitTest(e,t,n,r){return this.texts.hit(t.id,e,r)||this.hitShape(e,t,n,r)}hitShape(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}},Dh=3.5,Oh=1.5,kh=8,Ah=[{value:`normal`,label:`Normal`},{value:`arrow`,label:`Arrow`}],jh={leftEnd:{kind:`choice`,label:`Left end`,default:`normal`,choices:Ah},rightEnd:{kind:`choice`,label:`Right end`,default:`normal`,choices:Ah}},Mh={showMiddlePoint:{kind:`boolean`,label:`Show middle point`,default:!1},showPriceRange:{kind:`boolean`,label:`Show price range`,default:!1},showBarsRange:{kind:`boolean`,label:`Show bars range`,default:!1},showDateRange:{kind:`boolean`,label:`Show date and time range`,default:!1},showAngle:{kind:`boolean`,label:`Show angle`,default:!1},alwaysShowStats:{kind:`boolean`,label:`Always show stats`,default:!1},statsPosition:{kind:`choice`,label:`Stats position`,default:`right`,choices:[{value:`left`,label:`Left`},{value:`center`,label:`Center`},{value:`right`,label:`Right`}]}};function Nh(e,t,n,r,i=1){let a=Cn(i),o=Math.atan2(n.y-t.y,n.x-t.x);e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(n.x-a*Math.cos(o-Math.PI/6),n.y-a*Math.sin(o-Math.PI/6)),e.lineTo(n.x-a*Math.cos(o+Math.PI/6),n.y-a*Math.sin(o+Math.PI/6)),e.closePath(),e.fillStyle=r,e.fill()}var Ph=1.5;function Fh(e,t,n,r,i=1){Math.hypot(n.x-t.x,n.y-t.y)<Cn(i)*Ph||Nh(e,t,n,r,i)}function Ih(e,t,n,r){let[i,a]=t;i.x===a.x&&i.y===a.y||(r(`leftEnd`)===`arrow`&&Nh(e,a,i,n,Number(e.lineWidth)||1),r(`rightEnd`)===`arrow`&&Nh(e,i,a,n,Number(e.lineWidth)||1))}function Lh(e,t,n,r,i){let a=[];i(`showPriceRange`)&&a.push(Cr(e.anchors[0].price,e.anchors[1].price,t)),i(`showBarsRange`)&&a.push(`${Er(e,0,1,t)} bars`);let o=i(`showDateRange`)?Dr(e,0,1,t):null;return o&&a.push(o),i(`showAngle`)&&a.push(`${Th(n,r).toFixed(1)}°`),a}function Rh(e,t,n,[r,i],a,o){let s={x:(r.x+i.x)/2,y:(r.y+i.y)/2};if(o(`showMiddlePoint`)&&(e.beginPath(),e.arc(s.x,s.y,Math.max(Dh,An(t.style.lineWidth)-1),0,Math.PI*2),e.fillStyle=Bn(),e.fill(),e.strokeStyle=t.style.color,e.lineWidth=Oh,e.setLineDash([]),e.stroke()),!a&&!o(`alwaysShowStats`))return;let c=Lh(t,n,r,i,o);if(c.length===0)return;let[l,u]=r.x<=i.x?[r,i]:[i,r],d=o(`statsPosition`);if(d===`center`){Or(e,c,s.x,s.y-kh,`center`,!0);return}let[f,p]=d===`left`?[l,u]:[u,l],m=f.y<=p.y;Or(e,c,d===`left`?f.x-kh:f.x+kh,f.y+(m?-kh:kh),d===`left`?`right`:`left`,m)}var zh=class extends J{descriptor={type:`trendLine`,name:`Trend Line`,requiredAnchors:2,text:!0,options:{...Vm(),...jh,...Mh}};segment(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t);return this.extendLine(n,r,t,this.option(e,`extendLeft`),this.option(e,`extendRight`))}render(e,t,n,r){if(this.texts.set(t.id,null),t.anchors.length<2)return;let[i,a]=this.segment(t,n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e);let o=this.optionsOf(t);Ih(e,[i,a],t.style.color,o),Rh(e,t,n,[this.anchorToPixel(t.anchors[0],n),this.anchorToPixel(t.anchors[1],n)],r,o),this.texts.set(t.id,xh(e,t.style,i,a,n.chartRect)),r&&this.renderAnchorHandles(e,t,n)}priceAt(e,t,n){if(e.anchors.length<2)return null;let r=this.linePriceAt(e.anchors[0],e.anchors[1],t,this.option(e,`extendLeft`),this.option(e,`extendRight`),kp(n));return r===null?null:[r]}texts=new vh;textBox(e){return this.texts.bounds(e.id)}hitTest(e,t,n,r){return this.texts.hit(t.id,e,r)||this.hitShape(e,t,n,r)}hitShape(e,t,n,r){if(t.anchors.length<2)return!1;let[i,a]=this.segment(t,n);return this.distanceToLine(e,i,a)<=r}},Bh=class extends J{descriptor={type:`horizontalLine`,name:`Horizontal Line`,requiredAnchors:1,text:!0,options:Hm,axisSpan:`price`};priceAt(e){return e.anchors.length<1?null:[e.anchors[0].price]}render(t,n,r,i){if(this.texts.set(n.id,null),n.anchors.length<1)return;let a=e.T(n.anchors[0].price,r),{chartRect:o}=r;this.applyLineStyle(t,n.style),this.strokeHorizontal(t,o.x,o.x+o.width,a),this.resetLineStyle(t),this.texts.set(n.id,xh(t,n.style,{x:o.x,y:a},{x:o.x+o.width,y:a})),this.option(n,`showPrice`)&&(t.fillStyle=kn(n.style.color),nr(t,xr(n.anchors[0].price,n.anchors[0].price,r),o.x,a,o.x+o.width,o.y)),i&&this.renderAnchorHandles(t,n,r)}texts=new vh;textBox(e){return this.texts.bounds(e.id)}hitTest(e,t,n,r){return this.texts.hit(t.id,e,r)||this.hitShape(e,t,n,r)}hitShape(t,n,r,i){if(n.anchors.length<1)return!1;let a=e.T(n.anchors[0].price,r);return Math.abs(t.y-a)<=i&&t.x>=r.chartRect.x&&t.x<=r.chartRect.x+r.chartRect.width}},Vh=class extends J{descriptor={type:`horizontalRay`,name:`Horizontal Ray`,requiredAnchors:1,text:!0,options:Hm,axisSpan:`price`};priceAt(e,t){return e.anchors.length<1||t<e.anchors[0].time?null:[e.anchors[0].price]}render(e,t,n,r){if(this.texts.set(t.id,null),t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),a=i.y,{chartRect:o}=n;if(this.applyLineStyle(e,t.style),this.strokeHorizontal(e,i.x,o.x+o.width,a),this.resetLineStyle(e),this.texts.set(t.id,xh(e,t.style,i,{x:o.x+o.width,y:a},o)),this.option(t,`showPrice`)){e.fillStyle=kn(t.style.color);let r=i.x+An(t.style.lineWidth);nr(e,xr(t.anchors[0].price,t.anchors[0].price,n),r,a,o.x+o.width,o.y)}r&&this.renderAnchorHandles(e,t,n)}texts=new vh;textBox(e){return this.texts.bounds(e.id)}hitTest(e,t,n,r){return this.texts.hit(t.id,e,r)||this.hitShape(e,t,n,r)}hitShape(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n);return Math.abs(e.y-i.y)<=r&&e.x>=i.x-r&&e.x<=n.chartRect.x+n.chartRect.width}},Hh=4,Uh=class extends J{descriptor={type:`verticalLine`,name:`Vertical Line`,requiredAnchors:1,text:!0,axisSpan:`time`,options:{showTime:{kind:`boolean`,label:`Show time`,default:!1}}};render(e,t,n,r){if(this.texts.set(t.id,null),t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),{chartRect:a}=n,o=a.y+a.height;this.applyLineStyle(e,t.style),this.strokeVertical(e,i.x,a.y,o),this.resetLineStyle(e);let s=this.option(t,`showTime`)?this.timeText(t,n):null,c=s?o-Hh*2-ir():o;if(this.texts.set(t.id,xh(e,t.style,{x:i.x,y:c},{x:i.x,y:a.y})),s){e.font=N(`label`);let n=e.measureText(s).width+12;lr(e,s,i.x-n/2,o-Hh-ir()/2,t.style.color)}r&&this.renderAnchorHandles(e,t,n)}timeText(e,t){if(!t.formatTime)return null;try{return t.formatTime(e.anchors[0].time)}catch{return null}}texts=new vh;textBox(e){return this.texts.bounds(e.id)}hitTest(e,t,n,r){return this.texts.hit(t.id,e,r)||this.hitShape(e,t,n,r)}hitShape(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n),{chartRect:a}=n;return Math.abs(e.x-i.x)<=r&&e.y>=a.y&&e.y<=a.y+a.height}},Wh=class extends J{descriptor={type:`ray`,name:`Ray`,requiredAnchors:2,text:!0,options:Mh};render(e,t,n,r){if(this.texts.set(t.id,null),t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=a.x-i.x,c=a.y-i.y,l=Math.hypot(s,c);if(l===0)return;let u=Math.hypot(o.width,o.height)*2,d=i.x+s/l*u,f=i.y+c/l*u;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(d,f),e.stroke(),this.resetLineStyle(e),Rh(e,t,n,[i,a],r,this.optionsOf(t)),this.texts.set(t.id,xh(e,t.style,i,{x:d,y:f},o)),r&&this.renderAnchorHandles(e,t,n)}priceAt(e,t,n){if(e.anchors.length<2)return null;let r=this.linePriceAt(e.anchors[0],e.anchors[1],t,!1,!0,kp(n));return r===null?null:[r]}texts=new vh;textBox(e){return this.texts.bounds(e.id)}hitTest(e,t,n,r){return this.texts.hit(t.id,e,r)||this.hitShape(e,t,n,r)}hitShape(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;return((e.x-i.x)*o+(e.y-i.y)*s)/(o*o+s*s)<0?!1:this.distanceToInfiniteLine(e,i,a)<=r}},Gh=class extends J{descriptor={type:`extendedLine`,name:`Extended Line`,requiredAnchors:2,text:!0,options:Mh};render(e,t,n,r){if(this.texts.set(t.id,null),t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=a.x-i.x,c=a.y-i.y,l=Math.hypot(s,c);if(l===0)return;let u=Math.hypot(o.width,o.height)*2,d=i.x-s/l*u,f=i.y-c/l*u,p=i.x+s/l*u,m=i.y+c/l*u;this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(d,f),e.lineTo(p,m),e.stroke(),this.resetLineStyle(e),Rh(e,t,n,[i,a],r,this.optionsOf(t)),this.texts.set(t.id,xh(e,t.style,{x:d,y:f},{x:p,y:m},o)),r&&this.renderAnchorHandles(e,t,n)}priceAt(e,t,n){if(e.anchors.length<2)return null;let r=this.linePriceAt(e.anchors[0],e.anchors[1],t,!0,!0,kp(n));return r===null?null:[r]}texts=new vh;textBox(e){return this.texts.bounds(e.id)}hitTest(e,t,n,r){return this.texts.hit(t.id,e,r)||this.hitShape(e,t,n,r)}hitShape(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToInfiniteLine(e,i,a)<=r}},Kh=.7,qh=.5,Jh=class extends J{descriptor={type:`parallelChannel`,name:`Parallel Channel`,requiredAnchors:3,fill:!0,options:{...Vm(),middleLine:{kind:`boolean`,label:`Middle line`,default:!1}}};lines(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t),i=this.option(e,`extendLeft`),a=this.option(e,`extendRight`),o=this.extendLine(n,r,t,i,a);if(e.anchors.length<3)return{base:o,parallel:null,middle:null,corners:null};let s=this.anchorToPixel(e.anchors[2],t),c=r.x-n.x,l=Math.abs(c)<qh,u=l?s.y:n.y+(s.x-n.x)*(r.y-n.y)/c,d=l?{x:s.x-n.x,y:0}:{x:0,y:s.y-u},f=(e,t)=>({x:e.x+d.x*t,y:e.y+d.y*t}),p=f(n,1),m=f(r,1);return{base:o,parallel:this.extendLine(p,m,t,i,a),middle:this.option(e,`middleLine`)?this.extendLine(f(n,.5),f(r,.5),t,i,a):null,corners:[n,r,m,p]}}handlePoints(e,t){let n=super.handlePoints(e,t),{corners:r}=this.lines(e,t);if(!r||n.length<3)return n;let[,,i,a]=r;return[n[0],n[1],{x:(a.x+i.x)/2,y:(a.y+i.y)/2}]}render(e,t,n,r){if(t.anchors.length<2)return;let{base:i,parallel:a,middle:o,corners:s}=this.lines(t,n);if(s&&t.style.fillColor){e.fillStyle=P(t.style),e.beginPath(),e.moveTo(s[0].x,s[0].y);for(let t of s.slice(1))e.lineTo(t.x,t.y);e.closePath(),e.fill()}this.applyLineStyle(e,t.style);for(let t of[i,a])t&&(e.beginPath(),e.moveTo(t[0].x,t[0].y),e.lineTo(t[1].x,t[1].y),e.stroke());o&&(e.setLineDash(Pn(`dashed`,t.style.lineWidth)),e.lineCap=`butt`,e.globalAlpha=Kh,e.beginPath(),e.moveTo(o[0].x,o[0].y),e.lineTo(o[1].x,o[1].y),e.stroke(),e.globalAlpha=1),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}priceAt(e,t,n){if(e.anchors.length<3)return null;let[r,i,a]=e.anchors,o=kp(n),s=this.lineValueAt(r,i,t,this.option(e,`extendLeft`),this.option(e,`extendRight`),o),c=this.lineValueAt(r,i,a.time,!0,!0,o);if(s===null||c===null)return null;let l=o.value(a.price)-c,u=[s,s+l];return this.option(e,`middleLine`)&&u.push(s+l/2),u.map(o.price)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let{base:i,parallel:a,middle:o}=this.lines(t,n);return[i,a,o].some(t=>t!==null&&this.distanceToLine(e,t[0],t[1])<=r)}},Yh=2,Xh=.8,Zh=64;function Qh(e,t,n){let r=Math.max(0,Math.round(Math.min(t,n))),i=Math.min(e.length-1,Math.round(Math.max(t,n))),a=i-r+1;if(a<2)return null;let o=0,s=0,c=0,l=0;for(let t=r;t<=i;t++){let n=e[t].close;o+=t,s+=n,c+=t*t,l+=t*n}let u=a*c-o*o;if(u===0)return null;let d=(a*l-o*s)/u,f=(s-d*o)/a,p=e=>f+d*e,m=0;for(let t=r;t<=i;t++)m+=(e[t].close-p(t))**2;return{from:r,to:i,slope:d,intercept:f,deviation:Math.sqrt(m/a),at:p}}var $h=class extends J{descriptor={type:`regressionChannel`,name:`Regression Channel`,requiredAnchors:2,fill:!0};dataGetter=null;dataRevision=()=>0;fits=new Map;fitsFor={data:null,length:0,revision:-1};setDataGetter(e,t=()=>0){this.dataGetter=e,this.dataRevision=t,this.fits.clear()}fit(t,n){let r=this.dataGetter?.();if(!r||r.length<2||t.anchors.length<2)return null;let i=this.dataRevision(),a=this.fitsFor;(a.data!==r||a.length!==r.length||a.revision!==i)&&(this.fits.clear(),this.fitsFor={data:r,length:r.length,revision:i});let o=Math.round(e.D(t.anchors[0].time,n)),s=Math.round(e.D(t.anchors[1].time,n)),c=`${o}:${s}`,l=this.fits.get(c);return l===void 0&&(this.fits.size>=Zh&&this.fits.clear(),l=Qh(r,o,s),this.fits.set(c,l)),l}lines(t,n){let r=this.fit(t,n);if(!r)return{middle:[this.anchorToPixel(t.anchors[0],n),this.anchorToPixel(t.anchors[1],n)],upper:null,lower:null};let i=t=>[{x:e.b(r.from,n),y:e.T(r.at(r.from)+t,n)},{x:e.b(r.to,n),y:e.T(r.at(r.to)+t,n)}],a=r.deviation*Yh;return{middle:i(0),upper:i(a),lower:i(-a)}}handlePoints(t,n){let r=this.fit(t,n);return r?t.anchors.map(t=>{let i=Math.max(r.from,Math.min(r.to,Math.round(e.D(t.time,n))));return{x:e.b(i,n),y:e.T(r.at(i),n)}}):super.handlePoints(t,n)}render(e,t,n,r){if(t.anchors.length<2)return;let{middle:i,upper:a,lower:o}=this.lines(t,n);a&&o&&t.style.fillColor&&(e.fillStyle=P(t.style),e.beginPath(),e.moveTo(a[0].x,a[0].y),e.lineTo(a[1].x,a[1].y),e.lineTo(o[1].x,o[1].y),e.lineTo(o[0].x,o[0].y),e.closePath(),e.fill()),this.applyLineStyle(e,t.style);for(let t of[a,o])t&&(e.beginPath(),e.moveTo(t[0].x,t[0].y),e.lineTo(t[1].x,t[1].y),e.stroke());a&&(e.setLineDash(Pn(`dashed`,t.style.lineWidth)),e.lineCap=`butt`,e.globalAlpha=Xh),e.beginPath(),e.moveTo(i[0].x,i[0].y),e.lineTo(i[1].x,i[1].y),e.stroke(),e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let{middle:i,upper:a,lower:o}=this.lines(t,n);return[i,a,o].some(t=>t!==null&&this.distanceToLine(e,t[0],t[1])<=r)}},eg=1,tg=.06,ng=3,rg=.8;function ig(e,n,r,i,a=e=>e.toFixed(2),o=`en-US`){let s=e*100,c=`${(0,t.formatPrice)(s,Math.abs(s-Math.round(s))<1e-9?0:eg,o)}%`,l=a(n);return r&&i?`${c} (${l})`:r?c:i?l:``}function ag(t,n,r,i,a,o){let s=a.x1-a.x0;if(a.background&&i.length>1){let o=[...i].sort((e,t)=>e.level.value-t.level.value);for(let i=0;i<o.length-1;i++){let c=e.T(o[i].price,r),l=e.T(o[i+1].price,r);t.fillStyle=o[i+1].level.color??P(n.style,1),t.globalAlpha=tg,t.fillRect(a.x0,Math.min(c,l),s,Math.abs(l-c))}t.globalAlpha=1}t.font=N(`label`),t.textBaseline=`bottom`,t.textAlign=a.labelPosition===`right`?`right`:`left`;let c=a.labelPosition===`right`?a.x1-4:a.x0+4,l=M().sizes.label,u=[],d=e=>e===0||e===1,f=i.map(({level:t,price:n})=>({level:t,price:n,y:e.T(n,r)}));for(let{level:r,y:i}of f){o(r.color??n.style.color),t.globalAlpha=d(r.value)?1:rg;let s=e._(t,i,Number(t.lineWidth)||1);t.lineWidth=s.width,t.beginPath(),t.moveTo(a.x0,s.y),t.lineTo(a.x1,s.y),t.stroke()}t.globalAlpha=1;let p=[...f].sort((e,t)=>Number(d(t.level.value))-Number(d(e.level.value)));for(let{level:e,price:i,y:o}of p){let s=ig(e.value,i,a.showLevels,a.showPrices,e=>xr(e,e,r),r.numberLocale);if(!s)continue;let f=t.measureText(s).width,p=a.labelPosition===`right`?c-f:c,m={left:p,right:p+f,top:o-ng-l,bottom:o-ng},h={left:p,right:p+f,top:o+ng,bottom:o+ng+l},g=$n(p,p+f,o+ng)+ng,_={left:p,right:p+f,top:g,bottom:g+l},v=Ar([m,h,_],u)??(d(e.value)?_:null);v&&(u.push(v),t.fillStyle=kn(e.color??n.style.color),t.textBaseline=`top`,F(t,s,c,v.top))}t.globalAlpha=1}var og=[5,4],sg=.8;function cg(e,t,n){t.length<2||(e.save(),e.strokeStyle=n,e.lineWidth=1,e.globalAlpha=sg,e.setLineDash(og),e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.stroke(),e.restore())}function lg(e){return e.map(({level:e,price:t})=>({level:{...e,color:void 0},price:t}))}function ug(t,n,r,i,a,o){return t.x<i-o||t.x>a+o?!1:r.some(({price:r})=>Math.abs(t.y-e.T(r,n))<=o)}var dg=zm([0,.236,.382,.5,.618,.786,1],[1.272,1.414,1.618,2.618,3.618,4.236]),fg=class extends J{descriptor={type:`fibRetracement`,name:`Fibonacci Retracement`,requiredAnchors:2,fill:!0,options:{levels:{kind:`levels`,label:`Levels`,default:dg},...Vm(!0,!0),reverse:{kind:`boolean`,label:`Reverse`,default:!1},...Wm,...Um,background:{kind:`boolean`,label:`Background`,default:!0}}};levels(e){let t=this.option(e,`reverse`),n=e.anchors[+!!t].price,r=e.anchors[+!t].price;return this.visibleLevels(e).map(e=>({level:e,price:n+(r-n)*e.value}))}span(e,t){let{chartRect:n}=t,r=this.anchorToPixel(e.anchors[0],t).x,i=this.anchorToPixel(e.anchors[1],t).x;return[this.option(e,`extendLeft`)?n.x:Math.min(r,i),this.option(e,`extendRight`)?n.x+n.width:Math.max(r,i)]}render(e,t,n,r){if(t.anchors.length<2)return;let[i,a]=this.span(t,n);this.option(t,`trendLine`)&&cg(e,t.anchors.slice(0,2).map(e=>this.anchorToPixel(e,n)),t.style.color),ag(e,t,n,this.option(t,`oneColor`)?lg(this.levels(t)):this.levels(t),{x0:i,x1:a,showLevels:this.option(t,`showLevels`),showPrices:this.option(t,`showPrices`),labelPosition:this.option(t,`labelPosition`),background:this.option(t,`background`)},n=>this.applyLineStyle(e,{...t.style,color:n})),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let[i,a]=this.span(t,n);return ug(e,n,this.levels(t),i,a,r)}},pg=zm([0,.618,1,1.618,2,2.618,3.618,4.236],[.382,.5,.786,1.272,1.414]),mg=class extends J{descriptor={type:`fibExtension`,name:`Fibonacci Extension`,requiredAnchors:3,fill:!0,options:{levels:{kind:`levels`,label:`Levels`,default:pg},...Vm(!0,!0),...Wm,...Um,background:{kind:`boolean`,label:`Background`,default:!1}}};levels(e){let t=e.anchors[1].price-e.anchors[0].price,n=e.anchors[2].price;return this.visibleLevels(e).map(e=>({level:e,price:n+t*e.value}))}span(e,t){let{chartRect:n}=t,r=e.anchors.map(e=>this.anchorToPixel(e,t).x);return[this.option(e,`extendLeft`)?n.x:Math.min(...r),this.option(e,`extendRight`)?n.x+n.width:Math.max(...r)]}render(e,t,n,r){if(t.anchors.length<3){if(t.anchors.length===2){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e)}return}let[i,a]=this.span(t,n);this.option(t,`trendLine`)&&cg(e,t.anchors.slice(0,3).map(e=>this.anchorToPixel(e,n)),t.style.color),ag(e,t,n,this.option(t,`oneColor`)?lg(this.levels(t)):this.levels(t),{x0:i,x1:a,showLevels:this.option(t,`showLevels`),showPrices:this.option(t,`showPrices`),labelPosition:this.option(t,`labelPosition`),background:this.option(t,`background`)},n=>this.applyLineStyle(e,{...t.style,color:n})),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let[i,a]=this.span(t,n);return ug(e,n,this.levels(t),i,a,r)}},hg=new Set([4,5,6,7]),gg=class extends J{descriptor={type:`rectangle`,name:`Rectangle`,requiredAnchors:2,fill:!0,text:!0};render(e,t,n,r){if(this.texts.set(t.id,null),t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.min(i.y,a.y),c=Math.abs(a.x-i.x),l=Math.abs(a.y-i.y);t.style.fillColor&&(e.fillStyle=P(t.style),e.fillRect(o,s,c,l)),this.applyLineStyle(e,t.style),e.strokeRect(o,s,c,l),this.resetLineStyle(e),this.texts.set(t.id,Sh(e,t.style,{x:o,y:s,width:c,height:l})),r&&this.renderBoxHandles(e,t,n)}handlePoints(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t),i={x:(n.x+r.x)/2,y:(n.y+r.y)/2};return[n,r,{x:n.x,y:r.y},{x:r.x,y:n.y},{x:i.x,y:n.y},{x:i.x,y:r.y},{x:n.x,y:i.y},{x:r.x,y:i.y}]}renderBoxHandles(e,t,n){yp(e,t,this.handlePoints(t,n),{sides:hg})}hitTestAnchor(e,t,n,r){if(t.anchors.length<2)return super.hitTestAnchor(e,t,n,r);let i=-1,a=r;return this.handlePoints(t,n).forEach((t,n)=>{let o=Math.hypot(e.x-t.x,e.y-t.y);(o<a||i<0&&o<=r)&&(i=n,a=o)}),i}moveHandle(e,t,n){let[r,i]=e.anchors,a={0:[n,i],1:[r,n],2:[{time:n.time,price:r.price},{time:i.time,price:n.price}],3:[{time:r.time,price:n.price},{time:n.time,price:i.price}],4:[{time:r.time,price:n.price},i],5:[r,{time:i.time,price:n.price}],6:[{time:n.time,price:r.price},i],7:[r,{time:n.time,price:i.price}]};return a[t]?{...e,anchors:a[t]}:e}texts=new vh;textBox(e){return this.texts.bounds(e.id)}hitTest(e,t,n,r){return this.texts.hit(t.id,e,r)||this.hitShape(e,t,n,r)}hitShape(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x)-r,s=Math.min(i.y,a.y)-r,c=Math.max(i.x,a.x)+r,l=Math.max(i.y,a.y)+r;if(e.x<o||e.x>c||e.y<s||e.y>l)return!1;let u=Math.min(i.x,a.x)+r,d=Math.min(i.y,a.y)+r,f=Math.max(i.x,a.x)-r,p=Math.max(i.y,a.y)-r;return!(e.x>u&&e.x<f&&e.y>d&&e.y<p)||!!t.style.fillColor}},_g=class extends J{descriptor={type:`ellipse`,name:`Ellipse`,requiredAnchors:2,fill:!0};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=(i.x+a.x)/2,s=(i.y+a.y)/2,c=Math.abs(a.x-i.x)/2,l=Math.abs(a.y-i.y)/2;e.beginPath(),e.ellipse(o,s,Math.max(c,1),Math.max(l,1),0,0,Math.PI*2),t.style.fillColor&&(e.fillStyle=P(t.style),e.fill()),this.applyLineStyle(e,t.style),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}handlePoints(e,t){if(e.anchors.length<2)return super.handlePoints(e,t);let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t),i={x:(n.x+r.x)/2,y:(n.y+r.y)/2};return[{x:i.x,y:n.y},{x:i.x,y:r.y},{x:n.x,y:i.y},{x:r.x,y:i.y}]}moveHandle(e,t,n){let[r,i]=e.anchors,a={0:[{time:r.time,price:n.price},i],1:[r,{time:i.time,price:n.price}],2:[{time:n.time,price:r.price},i],3:[r,{time:n.time,price:i.price}]};return a[t]?{...e,anchors:a[t]}:e}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=(i.x+a.x)/2,s=(i.y+a.y)/2,c=Math.max(Math.abs(a.x-i.x)/2,1),l=Math.max(Math.abs(a.y-i.y)/2,1),u=(e.x-o)/c,d=(e.y-s)/l,f=Math.sqrt(u*u+d*d),p=r/Math.max(Math.min(c,l),4);return t.style.fillColor?f<=1+p:Math.abs(f-1)<=p}},vg=class extends J{descriptor={type:`triangle`,name:`Triangle`,requiredAnchors:3,fill:!0};render(e,t,n,r){if(t.anchors.length<3){if(t.anchors.length===2){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),this.resetLineStyle(e)}return}let i=t.anchors.map(e=>this.anchorToPixel(e,n));e.beginPath(),e.moveTo(i[0].x,i[0].y),e.lineTo(i[1].x,i[1].y),e.lineTo(i[2].x,i[2].y),e.closePath(),t.style.fillColor&&(e.fillStyle=P(t.style),e.fill()),this.applyLineStyle(e,t.style),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let i=t.anchors.map(e=>this.anchorToPixel(e,n));for(let t=0;t<3;t++){let n=(t+1)%3;if(this.distanceToLine(e,i[t],i[n])<=r)return!0}return!1}};function yg(e,t,n){let r=1/0;return t.x>0&&(r=Math.min(r,(n.x+n.width-e.x)/t.x)),t.x<0&&(r=Math.min(r,(n.x-e.x)/t.x)),t.y>0&&(r=Math.min(r,(n.y+n.height-e.y)/t.y)),t.y<0&&(r=Math.min(r,(n.y-e.y)/t.y)),Number.isFinite(r)?Math.max(0,r):0}function bg(e,t,n){return{x:e.x+t.x*n,y:e.y+t.y*n}}function xg(e,t){let{origin:n,b:r,c:i,dir:a}=e,o=[n,r,i].map(e=>[e,bg(e,a,yg(e,a,t))]);return[[r,i],...o]}var Sg=class extends J{descriptor={type:`pitchfork`,name:`Andrews' Pitchfork`,requiredAnchors:3,fill:!0};origin(e,t){return e}fork(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t),i=this.anchorToPixel(e.anchors[2],t),a=this.origin(n,r),o={x:(r.x+i.x)/2,y:(r.y+i.y)/2},s=o.x-a.x,c=o.y-a.y,l=Math.hypot(s,c)||1;return{pivot:n,origin:a,b:r,c:i,dir:{x:s/l,y:c/l}}}render(e,t,n,r){if(t.anchors.length<3){t.anchors.length===2&&this.renderFirstLeg(e,t,n);return}let i=this.fork(t,n),a=n.chartRect;this.fillTines(e,t,i,a),this.renderOriginGuide(e,t,i),this.applyLineStyle(e,t.style);for(let[t,n]of xg(i,a))this.strokeSegment(e,t,n);this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}renderFirstLeg(e,t,n){let r=this.anchorToPixel(t.anchors[0],n),i=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),this.strokeSegment(e,r,i),this.resetLineStyle(e)}fillTines(e,t,n,r){let{b:i,c:a,dir:o}=n,s=Math.max(yg(i,o,r),yg(a,o,r));if(s<=0)return;e.save(),e.beginPath(),e.rect(r.x,r.y,r.width,r.height),e.clip(),e.fillStyle=P(t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y);let c=bg(a,o,s),l=bg(i,o,s);e.lineTo(c.x,c.y),e.lineTo(l.x,l.y),e.closePath(),e.fill(),e.restore()}renderOriginGuide(e,t,n){let{pivot:r,origin:i}=n;r.x===i.x&&r.y===i.y||(this.applyGuideStyle(e,t.style.color,!0),this.strokeSegment(e,r,i),e.globalAlpha=1,e.setLineDash([]))}strokeSegment(e,t,n){e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(n.x,n.y),e.stroke()}hitTest(e,t,n,r){return t.anchors.length<3?!1:xg(this.fork(t,n),n.chartRect).some(([t,n])=>this.distanceToLine(e,t,n)<=r)}},Cg=class extends Sg{descriptor={type:`schiffPitchfork`,name:`Schiff Pitchfork`,requiredAnchors:3,fill:!0};origin(e,t){return{x:e.x,y:(e.y+t.y)/2}}},wg=class extends Sg{descriptor={type:`modifiedSchiffPitchfork`,name:`Modified Schiff Pitchfork`,requiredAnchors:3,fill:!0};origin(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}},Tg=5,Eg=3,Dg=1.25,Og=1.5,kg=[.5,.38,.62,.26,.74,.15,.85],Ag=8,jg=3;function Mg(e,t){let n=e[t-1],r=e[t+1],i=e[t];return!n&&!r?`above`:!n||!r?i.y<=(n??r).y?`above`:`below`:i.y<=(n.y+r.y)/2?`above`:`below`}function Ng(e){return An(e)+Tg}function Pg(e,t,n,r,i){let a=t===`above`?e.y-i-r:e.y+i;return{left:e.x-n/2,right:e.x+n/2,top:a,bottom:a+r}}function Fg(e,t,n,r,i){let a=Mg(e,t),o=Pg(e[t],a,n,r,i);return bn(o.left,o.top,n,r).top===o.top?o:Pg(e[t],a===`above`?`below`:`above`,n,r,i)}function Ig(e,t){return e.left<t.right&&t.left<e.right&&e.top<t.bottom&&t.top<e.bottom}function Lg(e,t,n,r){let i=e.measureText(t).width;if(!n)return{width:i,height:r};let a=2*Rg(i,r);return{width:a,height:a}}function Rg(e,t){return Math.max(e,t)/2+Eg}function zg(e,t,n,r,i){let a=a=>n.slice(0,t.length).map((n,o)=>{let s=a&&n.short?n.short:n.text,c=Lg(e,s,!!n.ring,r);return{text:s,ring:!!n.ring,first:!!n.first,box:Fg(t,o,c.width,c.height,i)}}).filter(e=>e.text),o=a(!1),s=o.some((e,t)=>o.slice(t+1).some(t=>Ig(e.box,t.box)))?a(!0):o,c=[...s.filter(e=>e.first),...s.filter(e=>!e.first)],l=[];for(let e of c)l.every(t=>!Ig(t.box,e.box))&&l.push(e);return s.filter(e=>l.includes(e))}function Bg(e,t,n,r,i){let a=zg(e,n,r,i,Ng(t.style.lineWidth)),o=kn(t.style.color);e.textAlign=`center`,e.textBaseline=`middle`;for(let n of a){let r=(n.box.left+n.box.right)/2,i=(n.box.top+n.box.bottom)/2;n.ring&&Vg(e,r,i,(n.box.right-n.box.left)/2,t.style.color),e.fillStyle=o,F(e,n.text,r,i),Hg(n.box)}return a.map(e=>e.box)}function Vg(e,t,n,r,i){e.save(),e.beginPath(),e.arc(t,n,r,0,Math.PI*2),e.fillStyle=M().background,e.fill(),e.strokeStyle=i,e.lineWidth=Dg,e.setLineDash([]),e.stroke(),e.restore()}function Hg(e){hn(e.left,e.top,e.right-e.left,e.bottom-e.top),Yn(e.left,e.top,e.right,e.bottom)}function Ug(e,t){let n=An(t)+Og;return e.map(e=>({left:e.x-n,right:e.x+n,top:e.y-n,bottom:e.y+n}))}function Wg(e,t,n,r,i){e.font=N(`mark`);let a=e.measureText(t).width,o=M().sizes.mark,s=o+jg,c=[0,s,-s].flatMap(e=>kg.map(t=>{let i=n.x+(r.x-n.x)*t,s=n.y+(r.y-n.y)*t+e;return{left:i-a/2,right:i+a/2,top:s-o/2,bottom:s+o/2}})),l=c.map(e=>({...e,left:e.left-Ag,right:e.right+Ag})),u=Ar(l,i);if(!u)return null;let d=c[l.indexOf(u)];return e.textAlign=`center`,e.textBaseline=`middle`,F(e,t,(d.left+d.right)/2,(d.top+d.bottom)/2),Hg(d),d}var Gg=[`0`,`i`,`ii`,`iii`,`iv`,`v`];function Kg(e,t){let n=/^[0-9]$/.test(e);switch(t){case`primary`:return n?e===`0`?`⓪`:String.fromCodePoint(9312+Number(e)-1):/^[A-Z]$/.test(e)?String.fromCodePoint(9398+e.charCodeAt(0)-65):e;case`intermediate`:return`(${e})`;case`minute`:return n?Gg[Number(e)]??e:e.toLowerCase();default:return e}}function qg(e,t){return t===`primary`?{text:e,ring:!0}:{text:Kg(e,t)}}var Jg={degree:{kind:`choice`,label:`Degree`,default:`minor`,choices:[{value:`primary`,label:`Primary`},{value:`intermediate`,label:`Intermediate`},{value:`minor`,label:`Minor`},{value:`minute`,label:`Minute`}]}},Yg=class extends J{render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors.map(e=>this.anchorToPixel(e,n));this.applyLineStyle(e,t.style),e.beginPath(),i.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.stroke(),this.resetLineStyle(e);let a=this.option(t,`degree`);e.font=N(`letter`,{weight:600}),Bg(e,t,i,this.labels.map(e=>qg(e,a)),M().sizes.letter),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){return t.anchors.length<2?!1:jp(e,t.anchors.map(e=>this.anchorToPixel(e,n)),r)}},Xg=class extends Yg{descriptor={type:`elliottWave`,name:`Elliott Wave`,requiredAnchors:8,options:Jg};labels=[`1`,`2`,`3`,`4`,`5`,`A`,`B`,`C`]},Zg=class extends Yg{descriptor={type:`elliottImpulse`,name:`Elliott Impulse Wave`,requiredAnchors:6,options:Jg};labels=[`0`,`1`,`2`,`3`,`4`,`5`]},Qg=class extends Yg{descriptor={type:`elliottCorrection`,name:`Elliott Correction Wave`,requiredAnchors:4,options:Jg};labels=[`0`,`A`,`B`,`C`]},$g=class extends Yg{descriptor={type:`elliottTriangle`,name:`Elliott Triangle Wave`,requiredAnchors:6,options:Jg};labels=[`0`,`A`,`B`,`C`,`D`,`E`]},e_=class extends Yg{descriptor={type:`elliottDoubleCombo`,name:`Elliott Double Combo Wave`,requiredAnchors:4,options:Jg};labels=[`0`,`W`,`X`,`Y`]},t_=class extends Yg{descriptor={type:`elliottTripleCombo`,name:`Elliott Triple Combo Wave`,requiredAnchors:6,options:Jg};labels=[`0`,`W`,`X`,`Y`,`X`,`Z`]},n_=.6,r_=6,i_=class extends J{descriptor={type:`priceRange`,name:`Price Range`,requiredAnchors:2};render(e,n,r,i){if(n.anchors.length<2)return;let a=this.anchorToPixel(n.anchors[0],r),o=this.anchorToPixel(n.anchors[1],r),s=Math.min(a.x,o.x),c=Math.abs(o.x-a.x),l=Math.min(a.y,o.y),u=Math.abs(o.y-a.y),d=M(),f=n.anchors[1].price>=n.anchors[0].price,p=n.style.color.toLowerCase()===t.DEFAULT_DRAWING_STYLE.color?f?d.rise:d.fall:n.style.color;e.fillStyle=(0,t.withAlpha)(p,an),e.fillRect(s,l,c,u),e.save(),this.applyGuideStyle(e,p),e.globalAlpha=n_,this.strokeCrispRect(e,s,l,c,u),e.restore();let m=s+c/2;this.applyLineStyle(e,{...n.style,color:p}),e.beginPath(),e.moveTo(m,a.y),e.lineTo(m,o.y),e.stroke(),this.resetLineStyle(e),Fh(e,{x:m,y:a.y},{x:m,y:o.y},p,n.style.lineWidth),e.font=N(`label`);let h=Cr(n.anchors[0].price,n.anchors[1].price,r),g=cr(e,h),_=ir(),v=f?l-r_-_:l+u+r_,y=bn(m-g/2,v,g,_);lr(e,h,y.left,y.top+_/2,p),i&&this.renderAnchorHandles(e,n,r)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y);return e.x>=o-r&&e.x<=s+r&&e.y>=c-r&&e.y<=l+r}},a_=.08,o_=6,s_=class extends J{descriptor={type:`dateRange`,name:`Date Range`,requiredAnchors:2};handlePoints(e,t){return this.timeHandles(e,t)}render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=Math.min(i.x,a.x),c=Math.max(i.x,a.x),l=o.y,u=o.y+o.height;e.fillStyle=P(t.style,a_),e.fillRect(s,l,c-s,u-l),this.applyLineStyle(e,t.style),this.strokeVertical(e,s,l,u),e.lineWidth=t.style.lineWidth,this.strokeVertical(e,c,l,u);let d=l+(u-l)/2;e.lineWidth=t.style.lineWidth,e.beginPath(),e.moveTo(i.x,d),e.lineTo(a.x,d),e.stroke(),this.resetLineStyle(e),Fh(e,{x:i.x,y:d},{x:a.x,y:d},t.style.color,t.style.lineWidth);let f=Er(t,0,1,n),p=Dr(t,0,1,n),m=p?`${f} bars · ${p}`:`${f} bars`;e.font=N(`label`);let h=cr(e,m),g=ir(),_=bn((s+c)/2-h/2,d-o_-g,h,g);lr(e,m,_.left,_.top+g/2,t.style.color),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n,s=Math.min(i.x,a.x),c=Math.max(i.x,a.x);return e.x>=s-r&&e.x<=c+r&&e.y>=o.y&&e.y<=o.y+o.height}},c_=class extends J{descriptor={type:`measure`,name:`Measure`,requiredAnchors:2};render(t,n,r,i){if(n.anchors.length<2)return;let a=this.anchorToPixel(n.anchors[0],r),o=this.anchorToPixel(n.anchors[1],r);this.applyLineStyle(t,n.style),t.lineCap=`butt`,t.setLineDash(Pn(`dashed`,n.style.lineWidth)),t.beginPath(),t.moveTo(a.x,a.y),t.lineTo(o.x,o.y),t.stroke(),this.resetLineStyle(t);let s=e.D(n.anchors[0].time,r),c=e.D(n.anchors[1].time,r),l=Math.max(0,Math.round(Math.abs(c-s))),u=[Cr(n.anchors[0].price,n.anchors[1].price,r),`${l} bars`];t.font=N(`label`),t.textAlign=`center`,t.textBaseline=`bottom`;let d=Math.max(...u.map(e=>t.measureText(e).width)),f=f_((a.x+o.x)/2,(a.y+o.y)/2,d,u.length,r);kr(t,f.x,f.y,f.width,f.height),t.fillStyle=M().ink;let p=f.x+f.width/2,m=f.y+f.height-d_;for(let e=0;e<u.length;e++)t.fillText(u[e],p,m-(u.length-1-e)*l_);i&&this.renderAnchorHandles(t,n,r)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}},l_=14,u_=6,d_=4;function f_(e,t,n,r,i){let{chartRect:a}=i,o=n+2*u_,s=r*l_+2*d_,c=p_(e-o/2,a.x,a.x+a.width-o),l=p_(t-s+d_,a.y,a.y+a.height-s);if(!Zn(c,l,c+o,l+s))return{x:c,y:l,width:o,height:s};let u=$n(c,c+o,l);return{x:c,y:u+s<=a.y+a.height?u:l,width:o,height:s}}function p_(e,t,n){return Math.max(t,Math.min(e,n))}var m_=500;function h_(e,t=`Text`){if(typeof e.style.text==`string`&&e.style.text.length>0)return e.style.text;let n=e.meta?.text;return typeof n==`string`&&n.length>0?n:t}var g_=class extends J{descriptor={type:`text`,name:`Text`,requiredAnchors:1,text:!0,fill:!0};boxes=new lh;render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),a={...Gm(t.style,{box:!1,border:!1,width:1/0}),maxLines:m_},o=rh(e,h_(t),i.x-8,i.y-6,a);this.boxes.set(t.id,o),ah(e,o,t.style.color,r)}handlePoints(){return[]}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n);return sh(e,this.boxes.get(t.id)??__(t,i),r)}textBox(e){return this.boxes.get(e.id)??null}};function __(e,t){let n=Sn(e.style),r=h_(e).split(`
|
|
4
4
|
`),i=Math.max(...r.map(e=>e.length));return{x:t.x-8,y:t.y-6,width:i*n*.6+16,height:r.length*n*1.3+12}}var v_=class extends J{descriptor={type:`arrow`,name:`Arrow`,requiredAnchors:2,text:!0};render(e,t,n,r){if(this.texts.set(t.id,null),t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),Nh(e,i,a,t.style.color,t.style.lineWidth),this.resetLineStyle(e),this.texts.set(t.id,xh(e,t.style,this.anchorToPixel(t.anchors[0],n),this.anchorToPixel(t.anchors[1],n),n.chartRect)),r&&this.renderAnchorHandles(e,t,n)}texts=new vh;textBox(e){return this.texts.bounds(e.id)}hitTest(e,t,n,r){return this.texts.hit(t.id,e,r)||this.hitShape(e,t,n,r)}hitShape(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}},y_=[{label:`8x1`,ratio:8},{label:`4x1`,ratio:4},{label:`3x1`,ratio:3},{label:`2x1`,ratio:2},{label:`1x1`,ratio:1},{label:`1x2`,ratio:.5},{label:`1x3`,ratio:1/3},{label:`1x4`,ratio:.25},{label:`1x8`,ratio:.125}],b_=4,x_=class extends J{descriptor={type:`gannFan`,name:`Gann Fan`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;if(Math.abs(o)<1)return;let c=s/o,l=o>0?1:-1,{chartRect:u}=n,d=l>0?u.x+u.width:u.x,f=u.y,p=u.y+u.height;e.font=N(`mark`);for(let{label:n,ratio:r}of y_){let a=c*r,o=d,s=i.y+a*(o-i.x);e.globalAlpha=1,r===1?this.applyLineStyle(e,t.style):this.applyGuideStyle(e,t.style.color),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(o,s),e.stroke();let m=Math.max(f,Math.min(p,s)),h=a===0||m===s?o:i.x+(m-i.y)/a;if(h<u.x||h>u.x+u.width)continue;e.globalAlpha=1,e.fillStyle=kn(t.style.color);let g=m===s;e.textAlign=g?l>0?`right`:`left`:`center`,e.textBaseline=m<=f+1?`top`:`bottom`;let _=g?h-l*b_:h,v=e.measureText(n).width,y=e.textAlign===`right`?_-v:e.textAlign===`left`?_:_-v/2;F(e,n,_,m<=f+1?$n(y,y+v,m)+b_:m-b_)}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=a.x-i.x,s=a.y-i.y;if(Math.abs(o)<1)return!1;let c=s/o,l=o>0?1:-1,{chartRect:u}=n,d=l>0?u.x+u.width:u.x;for(let{ratio:t}of y_){let n=c*t,a=d,o=i.y+n*(a-i.x);if(this.distanceToLine(e,i,{x:a,y:o})<=r)return!0}return!1}},S_=[0,.25,.333,.5,.667,.75,1].filter(e=>e>0&&e<1),C_=.3,w_=4,T_=2,E_=class extends J{descriptor={type:`gannBox`,name:`Gann Box`,requiredAnchors:2};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y),u=s-o,d=l-c;if(!(u<2||d<2)){this.applyLineStyle(e,t.style),this.strokeCrispRect(e,o,c,u,d),e.save(),this.applyGuideStyle(e,t.style.color),e.globalAlpha=C_;for(let t of S_)this.strokeHorizontal(e,o,s,c+d*t),e.lineWidth=1,this.strokeVertical(e,o+u*t,c,l),e.lineWidth=1;this.applyGuideStyle(e,t.style.color,!0),e.beginPath(),e.moveTo(o,c),e.lineTo(s,l),e.moveTo(s,c),e.lineTo(o,l),e.stroke(),e.restore(),this.resetLineStyle(e),this.renderLabels(e,t,{left:o,right:s,top:c,bottom:l,w:u,h:d}),r&&this.renderAnchorHandles(e,t,n)}}renderLabels(e,t,n){let r=M().sizes.mark;e.font=N(`mark`),e.fillStyle=kn(t.style.color);let i=[...S_].sort((e,t)=>Math.abs(e-.5)-Math.abs(t-.5)),a=[],o=e=>a.every(t=>e.x1+T_<=t.x0||t.x1+T_<=e.x0||e.y1+T_<=t.y0||t.y1+T_<=e.y0);for(let t of i){let i=`${Math.round(t*100)}%`,s=e.measureText(i).width,c=n.top+n.h*t,l={x0:n.left-w_-s,x1:n.left-w_,y0:c-r/2,y1:c+r/2};o(l)&&(a.push(l),e.textAlign=`right`,e.textBaseline=`middle`,F(e,i,l.x1,c));let u=n.left+n.w*t,d={x0:u-s/2,x1:u+s/2,y0:n.bottom+w_,y1:n.bottom+w_+r};o(d)&&(a.push(d),e.textAlign=`center`,e.textBaseline=`top`,F(e,i,u,d.y0))}}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),c=Math.min(i.y,a.y),l=Math.max(i.y,a.y);return Math.abs(e.x-o)<=r&&e.y>=c-r&&e.y<=l+r||Math.abs(e.x-s)<=r&&e.y>=c-r&&e.y<=l+r||Math.abs(e.y-c)<=r&&e.x>=o-r&&e.x<=s+r||Math.abs(e.y-l)<=r&&e.x>=o-r&&e.x<=s+r||this.distanceToLine(e,{x:o,y:c},{x:s,y:l})<=r||this.distanceToLine(e,{x:s,y:c},{x:o,y:l})<=r}},D_=6,O_=class extends J{descriptor={type:`anchoredVWAP`,name:`Anchored VWAP`,requiredAnchors:1,priceOnly:!0};dataGetter=null;dataRevision=()=>0;showBands=!0;setDataGetter(e,t=()=>0){this.dataGetter=e,this.dataRevision=t}setShowBands(e){this.showBands=e}handlePoints(t,n){let r=this.dataGetter?.(),i=Math.max(0,Math.round(e.D(t.anchors[0]?.time??0,n)));if(!r||t.anchors.length<1||i>=r.length)return super.handlePoints(t,n);let a=r[i],o=(a.high+a.low+a.close)/3;return[{x:e.b(i,n),y:e.T(o,n)}]}render(t,n,r,i){if(n.anchors.length<1||!this.dataGetter)return;let a=this.dataGetter(),o=Math.max(0,Math.round(e.D(n.anchors[0].time,r)));if(o>=a.length)return;let{vwap:s,upper1:c,lower1:l,upper2:u,lower2:d}=this.computeVWAP(a,o),{chartRect:f}=r,p=r.barWidth+r.barSpacing;if(this.applyLineStyle(t,n.style),t.lineWidth=n.style.lineWidth+.5,this.drawLine(t,s,o,r,f,p),this.showBands&&s.length>1&&(t.globalAlpha=.4,t.lineWidth=Math.max(.5,n.style.lineWidth*.6),t.setLineDash([4,3]),this.drawLine(t,c,o,r,f,p),this.drawLine(t,l,o,r,f,p),t.globalAlpha=.25,this.drawLine(t,u,o,r,f,p),this.drawLine(t,d,o,r,f,p),t.globalAlpha=1),this.resetLineStyle(t),s.length>0){let i=s[s.length-1],a=e.b(o+s.length-1,r),c=e.T(i,r);if(a>=f.x&&a<=f.x+f.width){t.fillStyle=n.style.color,t.font=N(`mark`,{weight:600}),t.textBaseline=`middle`;let e=`AVWAP ${xr(i,i,r)}`,o=bn(a+D_,c,t.measureText(e).width,0);t.textAlign=`left`,F(t,e,o.left,c)}}i&&this.renderAnchorHandles(t,n,r)}drawLine(t,n,r,i,a,o){t.beginPath();let s=!1;for(let c=0;c<n.length;c++){let l=e.b(r+c,i);if(l<a.x-o)continue;if(l>a.x+a.width+o)break;let u=e.T(n[c],i);s?t.lineTo(l,u):(t.moveTo(l,u),s=!0)}t.stroke()}vwapCache=null;computeVWAP(e,t){let n=e[e.length-1],r=this.dataRevision(),i=this.vwapCache;if(i&&i.data===e&&i.revision===r&&i.length===e.length&&i.startIdx===t&&i.lastClose===n?.close&&i.lastVolume===(n?.volume??0))return i.result;let a=this.computeVWAPUncached(e,t);return this.vwapCache={data:e,revision:r,length:e.length,startIdx:t,lastClose:n?.close,lastVolume:n?.volume??0,result:a},a}computeVWAPUncached(e,t){let n=e.length-t,r=Array(n),i=Array(n),a=Array(n),o=Array(n),s=Array(n),c=0,l=0,u=0;for(let d=0;d<n;d++){let n=e[t+d],f=(n.high+n.low+n.close)/3,p=n.volume??1;c+=f*p,l+=p,u+=f*f*p;let m=l>0?c/l:f;r[d]=m;let h=l>0?u/l-m*m:0,g=Math.sqrt(Math.max(0,h));i[d]=m+g,a[d]=m-g,o[d]=m+2*g,s[d]=m-2*g}return{vwap:r,upper1:i,lower1:a,upper2:o,lower2:s}}hitTest(t,n,r,i){if(n.anchors.length<1||!this.dataGetter)return!1;let a=this.dataGetter(),o=Math.max(0,Math.round(e.D(n.anchors[0].time,r)));if(o>=a.length)return!1;let{vwap:s}=this.computeVWAP(a,o);for(let n=1;n<s.length;n++){let a=e.b(o+n-1,r),c=e.T(s[n-1],r),l=e.b(o+n,r),u=e.T(s[n],r);if(this.distanceToLine(t,{x:a,y:c},{x:l,y:u})<=i)return!0}return!1}},k_=`#f2a93b`,A_=40,j_=1/3,M_=.7,N_=.45,P_=.2,F_=.5,I_=.5,L_=class extends J{descriptor={type:`volumeProfileRange`,name:`Volume Profile (Range)`,requiredAnchors:2,fill:!0,priceOnly:!0};dataGetter=null;dataRevision=()=>0;cached=null;setDataGetter(e,t=()=>0){this.dataGetter=e,this.dataRevision=t,this.cached=null}profile(t,n){if(t.anchors.length<2||!this.dataGetter)return null;let r=this.dataGetter(),i=Math.round(e.D(t.anchors[0].time,n)),a=Math.round(e.D(t.anchors[1].time,n)),o=Math.max(0,Math.min(i,a)),s=Math.min(r.length-1,Math.max(i,a));if(o>=r.length||s<0||o>s)return null;let c=this.dataRevision(),l=this.cached,u=l&&l.data===r&&l.length===r.length&&l.revision===c&&l.start===o&&l.end===s?l.rows:this.rowsOf(r,o,s);return this.cached={data:r,length:r.length,revision:c,start:o,end:s,rows:u},u?{startX:e.b(o,n),endX:e.b(s,n),left:e.b(o,n)-n.barWidth/2,right:e.b(s,n)+n.barWidth/2,top:e.T(u.pMax,n),bottom:e.T(u.pMin,n),pMin:u.pMin,binSize:u.binSize,bins:u.bins,maxBin:u.maxBin,poc:u.poc,valueLow:u.valueLow,valueHigh:u.valueHigh}:null}rowsOf(e,t,n){let r=1/0,i=-1/0;for(let a=t;a<=n;a++)e[a].low<r&&(r=e[a].low),e[a].high>i&&(i=e[a].high);if(!(r<i))return null;let a=(i-r)/A_,o=new Float64Array(A_);for(let i=t;i<=n;i++){let t=e[i],n=Math.max(0,Math.floor((t.low-r)/a)),s=Math.min(A_-1,Math.floor((t.high-r)/a)),c=(t.volume??1)/(s-n+1);for(let e=n;e<=s;e++)o[e]+=c}let s=0,c=0;for(let e=0;e<A_;e++)c+=o[e],o[e]>o[s]&&(s=e);if(o[s]===0)return null;let l=s,u=s,d=o[s];for(;d<c*M_&&(l>0||u<A_-1);){let e=l>0?o[l-1]:-1;(u<A_-1?o[u+1]:-1)>=e?d+=o[++u]:d+=o[--l]}return{start:t,end:n,pMin:r,pMax:i,binSize:a,bins:o,maxBin:o[s],poc:s,valueLow:l,valueHigh:u}}handlePoints(e,t){let n=this.profile(e,t);if(!n)return super.handlePoints(e,t);let r=e.anchors[0].time<=e.anchors[1].time;return[{x:r?n.startX:n.endX,y:n.top},{x:r?n.endX:n.startX,y:n.bottom}]}render(t,n,r,i){let a=this.profile(n,r);if(!a)return;let o=n.style.color,s=Fn(n.style)?n.style.fillColor:k_,c=Math.max(1,(a.right-a.left)*j_);t.save();for(let n=0;n<A_;n++){let i=e.T(a.pMin+(n+1)*a.binSize,r),l=e.T(a.pMin+n*a.binSize,r);t.globalAlpha=n>=a.valueLow&&n<=a.valueHigh?N_:P_,t.fillStyle=n===a.poc?s:o,t.fillRect(a.left,Math.min(i,l),a.bins[n]/a.maxBin*c,Math.max(1,Math.abs(l-i)-I_))}t.restore(),t.save(),this.applyGuideStyle(t,o),t.globalAlpha=F_,this.strokeCrispRect(t,a.left,a.top,a.right-a.left,a.bottom-a.top),t.restore();let l=a.pMin+(a.poc+.5)*a.binSize,u=e.T(l,r);t.save(),t.strokeStyle=s,t.lineWidth=1,t.setLineDash(Pn(`dashed`,1)),this.strokeHorizontal(t,a.left,a.right,u),t.setLineDash([]),t.fillStyle=kn(s),t.font=N(`mark`),t.textAlign=`left`,t.textBaseline=`bottom`;let d=`POC ${xr(l,l,r)}`;F(t,d,bn(a.right+4,u-2,t.measureText(d).width,0).left,u-2),t.restore(),i&&this.renderAnchorHandles(t,n,r)}hitTest(e,t,n,r){let i=this.profile(t,n);return i?e.x>=i.left-r&&e.x<=i.right+r&&e.y>=i.top-r&&e.y<=i.bottom+r:!1}},R_=[1,2,3,5,8,13,21,34,55],z_=.6,B_=4,V_=class extends J{descriptor={type:`fibTimeZones`,name:`Fibonacci Time Zones`,requiredAnchors:2,options:{levels:{kind:`levels`,label:`Levels`,default:Bm([0,...R_],[89,144])}}};handlePoints(e,t){return this.timeHandles(e,t)}render(t,n,r,i){if(n.anchors.length<2)return;let a=n.anchors[0],o=n.anchors[1].time-a.time;if(o===0)return;let{chartRect:s}=r;t.font=N(`label`),t.textBaseline=`top`,t.textAlign=`center`;let c=M().sizes.label,l=[];for(let{value:i,color:u}of this.visibleLevels(n)){this.applyLineStyle(t,{...n.style,color:u??n.style.color});let d=e.O(a.time+o*i,r);if(d<s.x||d>s.x+s.width)continue;t.globalAlpha=i===0||i===1?1:z_,this.strokeVertical(t,d,s.y,s.y+s.height),t.globalAlpha=1;let f=String(i),p=t.measureText(f).width/2,m=$n(d-p,d+p,s.y)+B_,h={left:d-p,right:d+p,top:m,bottom:m+c};Ar([h],l)&&(l.push(h),t.fillStyle=kn(u??n.style.color),F(t,f,d,m))}t.globalAlpha=1,this.resetLineStyle(t),i&&this.renderAnchorHandles(t,n,r)}hitTest(t,n,r,i){if(n.anchors.length<2)return!1;let a=n.anchors[0],o=n.anchors[1].time-a.time;if(o===0)return!1;let{chartRect:s}=r;if(t.y<s.y||t.y>s.y+s.height)return!1;for(let{value:s}of this.visibleLevels(n)){let n=e.O(a.time+o*s,r);if(Math.abs(t.x-n)<=i)return!0}return!1}},H_=.14,U_=.6,W_=40,G_=2,K_=.1,q_=100,J_=0x38d7ea4c68000,Y_=2,X_=2,Z_=4,Q_=6,$_=class extends J{descriptor={type:`riskReward`,name:`Long/Short Position`,priceOnly:!0,requiredAnchors:2,options:{rewardRatio:{kind:`number`,label:`Reward:risk`,default:2,min:K_,max:q_,step:.1},accountSize:{kind:`number`,label:`Account size`,default:1e3,min:0,max:J_},riskMode:{kind:`choice`,label:`Risk as`,default:`percent`,choices:[{value:`percent`,label:`Percent of account`},{value:`amount`,label:`Amount`}]},risk:{kind:`number`,label:`Risk`,default:1,min:0,max:J_},qtyDecimals:{kind:`number`,label:`Quantity decimals`,default:2,min:0,max:8,step:1},showLabels:{kind:`boolean`,label:`Show labels`,default:!0}}};geometry(e){let t=e.anchors[0].price,n=e.anchors[1].price,r=this.option(e,`rewardRatio`),i=Math.abs(t-n),a=n<t,o=a?t+i*r:t-i*r,s=this.option(e,`risk`),c=this.option(e,`riskMode`)===`amount`?s:this.option(e,`accountSize`)*s/100,l=i>0?c/i:0;return{entry:t,stop:n,target:o,ratio:r,isLong:a,qty:l,riskAmount:c,rewardAmount:l*i*r}}span(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t);return{x:Math.min(n.x,r.x),width:Math.max(Math.abs(r.x-n.x),W_),stopX:r.x}}handles(e,t){let{target:n}=this.geometry(e),r=this.anchorToPixel(e.anchors[0],t),i=this.anchorToPixel(e.anchors[1],t),a=this.anchorToPixel({time:e.anchors[1].time,price:n},t).y;return[r,i,{x:i.x,y:a}]}render(e,n,r,i){if(n.anchors.length<2)return;let a=this.geometry(n),{x:o,width:s}=this.span(n,r),[c,l,u]=this.handles(n,r),d=M();e.fillStyle=(0,t.withAlpha)(d.fall,H_),e.fillRect(o,Math.min(c.y,l.y),s,Math.abs(l.y-c.y)),e.fillStyle=(0,t.withAlpha)(d.rise,H_),e.fillRect(o,Math.min(c.y,u.y),s,Math.abs(u.y-c.y)),e.save();for(let[t,n]of[[l.y,d.fall],[u.y,d.rise]])this.applyGuideStyle(e,n),e.globalAlpha=U_,this.strokeHorizontal(e,o,o+s,t);e.restore(),this.applyLineStyle(e,n.style),e.setLineDash([]),this.strokeHorizontal(e,o,o+s,c.y),this.resetLineStyle(e);let{chartRect:f}=r,p=f.x,m=f.x+f.width;if(this.option(n,`showLabels`)&&o+s>=p&&o<=m){let i=r.pricePrecision??(0,t.autoPricePrecision)(Math.min(a.stop,a.target),Math.max(a.stop,a.target)),s=r.numberLocale??`en-US`,h=this.option(n,`qtyDecimals`),g=e=>a.entry===0?0:(e-a.entry)/a.entry*100,_=a.ratio.toLocaleString(s,{maximumFractionDigits:X_});e.font=N(`label`);let v=e=>(0,t.priceTagText)(e,r,i),y=e=>(0,t.formatPrice)(e,Y_,s),b=e=>`${e>=a.entry?`+`:`−`}${Sr(Math.abs(g(e)),r)}%`,x=ir()+2,S=ir()/2,C=e=>{let t=e<c.y,n=e+(t?-1:1)*(S+2),r=t?Math.min(n,c.y-x):Math.max(n,c.y+x);return Math.min(Math.max(r,f.y+S),f.y+f.height-S)},w=({text:t,y:n,start:r})=>{let i=cr(e,t),a=Math.max(p+4,Math.min(Math.max(o+4,r??-1/0),m-4-i)),s=n-S;if(Qn(a,s,a+i,s+ir())){let e=(er(s,s+ir())??a)+Z_;e+i<=m-4&&!Qn(e,s,e+i,s+ir())?a=e:s=$n(a,a+i,s)+2}return Yn(a,s,a+i,s+ir()),{left:a,top:s}},T=[{text:`${a.isLong?`Long`:`Short`} · Qty ${(0,t.formatPrice)(a.qty,h,s)} · R:R ${_}`,y:c.y,color:n.style.color,start:c.x+An(n.style.lineWidth)+Q_}];Math.abs(l.y-c.y)>=1&&T.push({text:`Target ${v(a.target)} (${b(a.target)}) · ${y(a.rewardAmount)}`,y:C(u.y),color:d.rise},{text:`Stop ${v(a.stop)} (${b(a.stop)}) · ${y(a.riskAmount)}`,y:C(l.y),color:d.fall});let E=new Map([...T].sort((e,t)=>e.y-t.y).map(e=>[e,w(e)]));for(let t of T){let n=E.get(t);lr(e,t.text,n.left,n.top+S,t.color)}}i&&this.renderHandles(e,n,r)}renderHandles(e,t,n){yp(e,t,this.handles(t,n))}hitTestAnchor(e,t,n,r){return t.anchors.length<2?super.hitTestAnchor(e,t,n,r):this.handles(t,n).findIndex(t=>Math.hypot(e.x-t.x,e.y-t.y)<=r)}moveHandle(e,t,n){if(t!==G_){let r=e.anchors.map((e,r)=>r===t?{...n}:{...e});return{...e,anchors:r}}let{entry:r,isLong:i}=this.geometry(e),a=Math.abs(r-e.anchors[1].price),o=i?n.price-r:r-n.price,s=a>0?Math.min(q_,Math.max(K_,o/a)):K_;return{...e,options:{...e.options,rewardRatio:Math.round(s*100)/100}}}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let{x:i,width:a}=this.span(t,n),o=this.handles(t,n).map(e=>e.y);return e.x>=i-r&&e.x<=i+a+r&&e.y>=Math.min(...o)-r&&e.y<=Math.max(...o)+r}},ev=class extends J{descriptor={type:`crossLine`,name:`Cross Line`,requiredAnchors:1};render(e,t,n,r){if(t.anchors.length<1)return;let i=this.anchorToPixel(t.anchors[0],n),{chartRect:a}=n;this.applyLineStyle(e,t.style);let o=e.lineWidth;this.strokeHorizontal(e,a.x,a.x+a.width,i.y),e.lineWidth=o,this.strokeVertical(e,i.x,a.y,a.y+a.height),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<1)return!1;let i=this.anchorToPixel(t.anchors[0],n);return Math.abs(e.y-i.y)<=r||Math.abs(e.x-i.x)<=r}};function tv(e,t,n){let r=Dr(e,0,1,t),i=Er(e,0,1,t);return[Cr(e.anchors[0].price,e.anchors[1].price,t),r?`${i} bars, ${r}`:`${i} bars`,`${n.toFixed(1)}°`]}var nv=class extends J{descriptor={type:`infoLine`,name:`Info Line`,requiredAnchors:2,text:!0};render(e,t,n,r){if(this.texts.set(t.id,null),t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e);let o=tv(t,n,Th(i,a)),s=a.y<=i.y;Or(e,o,a.x+(a.x>=i.x?8:-8),a.y+(s?-6:6),a.x>=i.x?`left`:`right`,s),this.texts.set(t.id,xh(e,t.style,this.anchorToPixel(t.anchors[0],n),this.anchorToPixel(t.anchors[1],n),n.chartRect)),r&&this.renderAnchorHandles(e,t,n)}texts=new vh;textBox(e){return this.texts.bounds(e.id)}hitTest(e,t,n,r){return this.texts.hit(t.id,e,r)||this.hitShape(e,t,n,r)}hitShape(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return this.distanceToLine(e,i,a)<=r}},rv=.7,iv=10,av=[0,.236,.382,.5,.618,.786,1,1.618];function ov(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=r*r+i*i;if(a===0)return{x:n.x-e.x,y:n.y-e.y};let o=((n.x-e.x)*r+(n.y-e.y)*i)/a;return{x:n.x-(e.x+o*r),y:n.y-(e.y+o*i)}}function sv(e,t,n,r){let i=ov(e,t,n);return[{x:e.x+i.x*r,y:e.y+i.y*r},{x:t.x+i.x*r,y:t.y+i.y*r}]}var cv=class extends J{descriptor={type:`fibChannel`,name:`Fibonacci Channel`,requiredAnchors:3,options:{levels:{kind:`levels`,label:`Levels`,default:zm(av,[2.618,3.618,4.236])}}};render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);if(t.anchors.length<3){this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),this.resetLineStyle(e);return}let o=this.anchorToPixel(t.anchors[2],n);e.font=N(`label`),e.textAlign=`right`,e.textBaseline=`middle`;let s=this.visibleLevels(t);for(let{value:n,color:r}of s){let[s,c]=sv(i,a,o,n);this.applyLineStyle(e,{...t.style,color:r??t.style.color}),e.globalAlpha=n===0||n===1?1:rv,e.beginPath(),e.moveTo(s.x,s.y),e.lineTo(c.x,c.y),e.stroke()}e.globalAlpha=1;let c=M().sizes.label,l=[],u=e=>e===0||e===1;for(let{value:n,color:r}of[...s].sort((e,t)=>Number(u(t.value))-Number(u(e.value)))){let[s,d]=sv(i,a,o,n),f=s.x<=d.x?s:d,p=String(n),m=e.measureText(p).width,h={left:f.x-iv-m,right:f.x-iv,top:f.y-c/2,bottom:f.y+c/2};!Ar([h],l)&&!u(n)||(l.push(h),e.fillStyle=kn(r??t.style.color),F(e,p,h.right,f.y))}this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<3)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),o=this.anchorToPixel(t.anchors[2],n);for(let{value:n}of this.visibleLevels(t)){let[t,s]=sv(i,a,o,n);if(this.distanceToLine(e,t,s)<=r)return!0}return!1}},lv=.4,uv=.8,dv=4,fv=[.25,.382,.5,.618,.75];function pv(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=Math.hypot(r,i);if(a===0)return null;let o=(n.chartRect.width+n.chartRect.height)*2;return{x:e.x+r/a*o,y:e.y+i/a*o}}function mv(e,t,n=fv){let r=[{level:1,kind:`diagonal`,point:t}];for(let i of n)r.push({level:i,kind:`price`,point:{x:t.x,y:e.y+(t.y-e.y)*i}}),r.push({level:i,kind:`time`,point:{x:e.x+(t.x-e.x)*i,y:t.y}});return r}var hv=class extends J{descriptor={type:`fibSpeedResistanceFan`,name:`Fib Speed Resistance Fan`,requiredAnchors:2,options:{levels:{kind:`levels`,label:`Levels`,default:zm(fv,[.236,.786])}}};targets(e,t,n){return mv(t,n,this.visibleLevels(e).map(e=>e.value))}colorOf(e,t){return this.visibleLevels(e).find(e=>e.value===t)?.color??e.style.color}render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);e.save(),this.applyGuideStyle(e,t.style.color),e.globalAlpha=lv,this.strokeCrispRect(e,Math.min(i.x,a.x),Math.min(i.y,a.y),Math.abs(a.x-i.x),Math.abs(a.y-i.y)),e.restore(),e.font=N(`label`);let o=a.x>=i.x,s=a.y>=i.y;for(let r of this.targets(t,i,a)){let a=pv(i,r.point,n);if(!a)continue;let c=r.kind===`diagonal`?t.style.color:this.colorOf(t,r.level);this.applyLineStyle(e,{...t.style,color:c,lineStyle:r.kind===`time`?`dashed`:t.style.lineStyle}),e.globalAlpha=r.kind===`diagonal`?1:uv,e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(a.x,a.y),e.stroke(),r.kind!==`diagonal`&&(e.globalAlpha=1,e.fillStyle=kn(c),r.kind===`price`?(e.textAlign=o?`left`:`right`,e.textBaseline=`middle`,F(e,String(r.level),r.point.x+(o?dv:-dv),r.point.y)):(e.textAlign=`center`,e.textBaseline=s?`top`:`bottom`,F(e,String(r.level),r.point.x,r.point.y+(s?dv:-dv))))}e.globalAlpha=1,this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);for(let o of this.targets(t,i,a)){let t=pv(i,o.point,n);if(t&&this.distanceToLine(e,i,t)<=r)return!0}return!1}},gv=class extends J{ratioLinks=[];triangles=[];render(e,t,n,r){if(t.anchors.length<2)return;let i=t.anchors.map(e=>this.anchorToPixel(e,n));t.anchors.length>=this.descriptor.requiredAnchors&&this.renderTriangles(e,t,i),this.applyLineStyle(e,t.style),e.beginPath(),e.moveTo(i[0].x,i[0].y);for(let t=1;t<i.length;t++)e.lineTo(i[t].x,i[t].y);e.stroke(),this.resetLineStyle(e),this.renderGuides(e,t,i),this.renderExtras(e,t,i,n);let a=this.renderPointLabels(e,t,i);this.renderRatios(e,t,i,[...Ug(i,t.style.lineWidth),...a]),r&&this.renderAnchorHandles(e,t,n)}renderExtras(e,t,n,r){}pointFont(){return{font:N(`letter`,{weight:600}),height:M().sizes.letter}}renderTriangles(e,t,n){e.fillStyle=P(t.style);for(let[t,r,i]of this.triangles)e.beginPath(),e.moveTo(n[t].x,n[t].y),e.lineTo(n[r].x,n[r].y),e.lineTo(n[i].x,n[i].y),e.closePath(),e.fill()}linksIn(e){return this.ratioLinks.filter(t=>Math.max(t.from,t.to,...t.num,...t.den)<e.length)}renderGuides(e,t,n){e.save(),this.applyGuideStyle(e,t.style.color,!0);for(let t of this.linksIn(n))e.beginPath(),e.moveTo(n[t.from].x,n[t.from].y),e.lineTo(n[t.to].x,n[t.to].y),e.stroke();e.restore()}renderRatios(e,t,n,r){let i=[...r];e.fillStyle=kn(t.style.color);for(let r of this.linksIn(n)){let a=Wg(e,jr(t,r.num,r.den),n[r.from],n[r.to],i);a&&i.push(a)}}renderPointLabels(e,t,n){let{font:r,height:i}=this.pointFont();return e.font=r,Bg(e,t,n,this.pointLabels.map(e=>typeof e==`string`?{text:e}:e),i)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=t.anchors.map(e=>this.anchorToPixel(e,n));for(let t=0;t<i.length-1;t++)if(this.distanceToLine(e,i[t],i[t+1])<=r)return!0;return!1}},_v=class extends gv{descriptor={type:`xabcdPattern`,name:`XABCD Pattern`,requiredAnchors:5,fill:!0};pointLabels=[`X`,`A`,`B`,`C`,`D`];ratioLinks=[{from:0,to:2,num:[1,2],den:[0,1]},{from:1,to:3,num:[2,3],den:[1,2]},{from:2,to:4,num:[3,4],den:[2,3]},{from:0,to:4,num:[1,4],den:[0,1]}];triangles=[[0,1,2],[2,3,4]]},vv=class extends gv{descriptor={type:`abcdPattern`,name:`ABCD Pattern`,requiredAnchors:4,fill:!0};pointLabels=[`A`,`B`,`C`,`D`];ratioLinks=[{from:0,to:2,num:[1,2],den:[0,1]},{from:1,to:3,num:[2,3],den:[1,2]}]},yv=class extends gv{descriptor={type:`headAndShoulders`,name:`Head and Shoulders`,requiredAnchors:7,fill:!0};pointLabels=[{text:``},{text:`Left Shoulder`,short:`LS`},{text:``},{text:`Head`,short:`H`,first:!0},{text:``},{text:`Right Shoulder`,short:`RS`},{text:``}];pointFont(){return{font:N(`label`,{weight:600,prose:!0}),height:M().sizes.label}}triangles=[[0,1,2],[2,3,4],[4,5,6]];renderExtras(e,t,n){if(n.length<5)return;let r=n[2],i=n[4],a=n[0],o=n[n.length-1],s=i.x===r.x?0:(i.y-r.y)/(i.x-r.x),c=e=>r.y+s*(e-r.x);e.strokeStyle=t.style.color,e.lineWidth=Math.max(1,t.style.lineWidth),e.setLineDash([6,4]),e.beginPath(),e.moveTo(a.x,c(a.x)),e.lineTo(o.x,c(o.x)),e.stroke(),e.setLineDash([])}},bv=class extends gv{descriptor={type:`threeDrives`,name:`Three Drives Pattern`,requiredAnchors:6};pointLabels=[``,`1`,`A`,`2`,`B`,`3`];ratioLinks=[{from:1,to:3,num:[2,3],den:[1,2]},{from:3,to:5,num:[4,5],den:[3,4]}]},xv=class extends gv{descriptor={type:`cypherPattern`,name:`Cypher Pattern`,requiredAnchors:5,fill:!0};pointLabels=[`X`,`A`,`B`,`C`,`D`];ratioLinks=[{from:0,to:2,num:[1,2],den:[0,1]},{from:0,to:3,num:[2,3],den:[0,1]},{from:0,to:4,num:[3,4],den:[0,3]}];triangles=[[0,1,2],[2,3,4]]},Sv=class extends J{descriptor={type:`circle`,name:`Circle`,requiredAnchors:2,fill:!0};geometry(e,t){let n=this.anchorToPixel(e.anchors[0],t),r=this.anchorToPixel(e.anchors[1],t);return{c:n,r:Math.hypot(r.x-n.x,r.y-n.y)}}render(e,t,n,r){if(t.anchors.length<2)return;let{c:i,r:a}=this.geometry(t,n);e.beginPath(),e.arc(i.x,i.y,a,0,Math.PI*2),t.style.fillColor&&(e.fillStyle=P(t.style),e.fill()),this.applyLineStyle(e,t.style),e.stroke(),this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let{c:i,r:a}=this.geometry(t,n),o=Math.hypot(e.x-i.x,e.y-i.y);return t.style.fillColor?o<=a+r:Math.abs(o-a)<=r}},Cv=.5;function wv(t,n){let r=n.data;if(!r||r.length===0)return null;let i=Math.round(e.D(t.anchors[0].time,n)),a=Math.round(e.D(t.anchors[1].time,n)),o=Math.max(0,Math.min(i,a)),s=Math.min(r.length-1,Math.max(i,a)),c=0;for(let e=o;e<=s;e++)c+=r[e].volume??0;return c}function Tv(e,n){let r=Dr(e,0,1,n),i=Er(e,0,1,n),a=[Cr(e.anchors[0].price,e.anchors[1].price,n),r?`${i} bars · ${r}`:`${i} bars`],o=wv(e,n);return o!==null&&a.push(`Vol ${(0,t.formatVolumeLoc)(o,n.numberLocale??`en-US`)}`),a}var Ev=class extends J{descriptor={type:`dateAndPriceRange`,name:`Date and Price Range`,requiredAnchors:2};render(e,n,r,i){if(n.anchors.length<2)return;let a=this.anchorToPixel(n.anchors[0],r),o=this.anchorToPixel(n.anchors[1],r),s=Math.min(a.x,o.x),c=Math.min(a.y,o.y),l=Math.abs(o.x-a.x),u=Math.abs(o.y-a.y),d=n.anchors[1].price>=n.anchors[0].price,f=M(),p=d?n.style.color:f.fall;e.fillStyle=d?P(n.style):(0,t.withAlpha)(f.fall,an),e.fillRect(s,c,l,u),e.save(),this.applyGuideStyle(e,p),e.globalAlpha=Cv,this.strokeCrispRect(e,s,c,l,u),e.restore(),this.applyLineStyle(e,{...n.style,color:p});let m=s+l/2,h=c+u/2;e.beginPath(),e.moveTo(m,a.y),e.lineTo(m,o.y),e.moveTo(a.x,h),e.lineTo(o.x,h),e.stroke(),this.resetLineStyle(e),Fh(e,{x:m,y:a.y},{x:m,y:o.y},p,n.style.lineWidth),Fh(e,{x:a.x,y:h},{x:o.x,y:h},p,n.style.lineWidth),Or(e,Tv(n,r),m,d?c-6:c+u+6,`center`,d),i&&this.renderAnchorHandles(e,n,r)}hitTest(e,t,n,r){if(t.anchors.length<2)return!1;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n);return e.x>=Math.min(i.x,a.x)-r&&e.x<=Math.max(i.x,a.x)+r&&e.y>=Math.min(i.y,a.y)-r&&e.y<=Math.max(i.y,a.y)+r}},Dv=400,Ov=2;function kv(e,t,n){let r=Math.abs(t.x-e.x);if(r<Ov)return[e.x];let i=n.chartRect.x+n.chartRect.width,a=[],o=Math.min(e.x,t.x);for(let e=o;e<=i&&a.length<Dv;e+=r)a.push(e);return a}var Av=class extends J{descriptor={type:`cyclicLines`,name:`Cyclic Lines`,requiredAnchors:2};handlePoints(e,t){return this.timeHandles(e,t)}render(e,t,n,r){if(t.anchors.length<2)return;let i=this.anchorToPixel(t.anchors[0],n),a=this.anchorToPixel(t.anchors[1],n),{chartRect:o}=n;this.applyLineStyle(e,t.style);for(let r of kv(i,a,n))r<o.x||(this.strokeVertical(e,r,o.y,o.y+o.height),e.lineWidth=t.style.lineWidth);this.resetLineStyle(e),r&&this.renderAnchorHandles(e,t,n)}hitTest(e,t,n,r){return t.anchors.length<2?!1:kv(this.anchorToPixel(t.anchors[0],n),this.anchorToPixel(t.anchors[1],n),n).some(t=>Math.abs(e.x-t)<=r)}},jv=240;function Mv(e){return Sn(e.style)}function Nv(e){return Gm(e.style,{box:!0,border:!0,width:jv,fill:!0})}function Pv(e,t,n,r){let i=Mv(e),a=Math.max(...t.split(`
|