"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[1485],{87795:e=>{const t=55296,s=127995,i=127999,r=[776,2359,2359,2367,2367,2984,3007,3021,3633,3635,3648,3657,4352,4449,4520];function n(e){if("string"!=typeof e)throw new Error("string cannot be undefined or null");const t=[];let s=0,i=0;for(;s=t&&e<=s}e.exports=n,e.exports.substr=function(e,t,s){const i=n(e);if(void 0===t)return e;if(t>=i.length)return"";const r=i.length-t;let o=t+(void 0===s?r:s);return o>t+r&&(o=void 0),i.slice(t,o).join("")}},63002:(e,t,s)=>{s.d(t,{HHistBasedValuesProvider:()=>f});var i=s(50335),r=s(50151),n=s(49483),o=s(5471),a=s(78861),l=s(56265),h=s(99481),c=s(11946),u=s(53660);function d(e,t="",s=""){return{id:t,index:e,orderIndex:e,title:s,value:"",visible:!1}}const p=n.CheckMobile.any(),_=(0,l.getVolumeFormatter)();class f{constructor(e,t,s=!1){this._emptyValues=[],this._study=e,this._model=t,this._emptyTitles=s,void 0!==this._study.metaInfo().graphics.hhists&&this._emptyValues.push(d(0),d(1),d(2))}getItems(){return this._emptyValues}getValues(e){const t=this._emptyValues.map((e=>({...e})));t.forEach((e=>{e.visible=this._study.isVisible(),e.value=u.notAvailable}));const s=this._study.properties().childs().inputs.childs().volume.value();switch(s){case h.HHistVolumeMode.UpDown:this._emptyTitles||(t[0].title="Up",t[1].title="Down",t[2].title="Total");break;case h.HHistVolumeMode.Total:this._emptyTitles||(t[0].title="Total"),t[1].visible=!1,t[2].visible=!1;break;case h.HHistVolumeMode.Delta:this._emptyTitles||(t[0].title="Delta",t[1].title="Max(Up, Down)",t[2].title="Total")}const n=this._study.priceScale(),a=this._model.timeScale();if(null===n||n.isEmpty()||a.isEmpty()||this._hideValues())return t;if(null===e||!isFinite(e)){const s=this._study.data().last();if(null===s)return t;e=s.index}const l=this._model.crosshairSource(),c=l.price;if(!isFinite(l.y)&&null===(e=function(e,t){const s=e.visibleBarsStrictRange()?.lastBar();if(!s)return null;const i=t.data().search(s,o.PlotRowSearchMode.NearestLeft);return i?i.index:null}(this._model.timeScale(),this._model.mainSeries())))return t;const d=function(e,t,s,i){if(0===e.size)return null;if(!s){const e=(0,r.ensureNotNull)(i.data().valueAt(t));s=i.barFunction()(e)}const n=function(e,t){let s=null ;return e.forEach(((e,i)=>{null!==i&&i<=t&&(null===s||i>s)&&(s=i)})),s}(e,t);if(null===n)return null;const o=e.get(n);if(!o||0===o.size)return null;return function(e,t){let s=null;return e.forEach((e=>{e.priceLow<=t&&t{e.value="0"})),t;const p=this._study.metaInfo().graphics.hhists;if(void 0===p)return t;if(void 0===p[d.styleId])return t;const f=this._study.properties().childs().graphics.childs().hhists?.childs()[d.styleId]?.childs(),m=e=>(0,i.isNumber)(e)?_.format(e):"";if(s!==h.HHistVolumeMode.Delta){if(d.rate.forEach(((e,s)=>{t[s].value=m(e),t[s].color=(0,r.ensureDefined)(f).colors[s].value()})),s===h.HHistVolumeMode.UpDown){const e=d.rate[0]+d.rate[1];t[2].value=m(e),t[2].color=(0,r.ensureDefined)(f).valuesColor.value()}}else{const e=d.rate[0]>d.rate[1]?0:1,s=(0,r.ensureDefined)(f).colors[e].value(),i=d.rate[0]+d.rate[1];[2*d.rate[e]-i,d.rate[e],i].forEach(((e,i)=>{t[i].value=m(e),t[i].color=s}))}return t}_hideValues(){return p&&(null===this._model.crosshairSource().pane||(0,c.isLineToolName)(a.tool.value())||null!==this._model.lineBeingEdited())}}},70954:(e,t,s)=>{s.d(t,{StudyBaseWindowView:()=>n});var i=s(40137),r=s(36313);class n extends i.DataWindowView{constructor(e,t){super(),this._invalidated=!0,this._study=e,this._model=t,this._valueProvider=this._createValuesProvider(e,t),this._items=this._valueProvider.getItems().map((e=>new i.DataWindowItem(e.id,e.title,"")))}update(e){"hover-change"!==e.type&&(this._invalidated=!0)}items(){return this._invalidated&&(this._updateImpl(),this._invalidated=!1),this._items}study(){return this._study}_updateImpl(){this._header=this._study.title(r.TitleDisplayTarget.DataWindow),this._title=this._study.title(r.TitleDisplayTarget.DataWindow,!1);const e=this._valueProvider.getValues(this._currentIndex());for(let t=0;t{s.d(t,{StudyChartFloatingTooltipView:()=>n});var i=s(87465),r=s(36313);class n{constructor(e,t){this._items=[],this._invalidated=!0,this._study=e,this._model=t}destroy(){}items(){return this._invalidated&&(this._updateImpl(),this._invalidated=!1),this._items}update(e){this._invalidated=!0}_updateImpl(){const e=this._study.chartFloatingTooltipValuesProvider(),t=this._model.crosshairSource().appliedIndex(),s=e.getValues(t),n=this._study.titleInParts(r.TitleDisplayTarget.StatusLine),o=n[0];let a="";if(n.length>1){const e=n[1];e.length>0&&(a=e.join(" "))}this._items=s.filter(i.notUndefined).filter((e=>e.visible)).map(((e,t)=>({titleText:0===t?o:"",titleInputs:0===t?a:"",value:e.value,valueColor:e.color})))}}},13212:(e,t,s)=>{s.d(t,{StudyDataWindowView:()=>a});var i=s(70954),r=s(71320),n=s(63002);class o{constructor(e,t){this._study=e,this._model=t, this._hhistBasedStudy=void 0!==e.metaInfo().graphics.hhists,this._valuesProvider=this._createValuesProvider(e,t)}getItems(){return this._valuesProvider.getItems()}getValues(e){const t=this._valuesProvider.getValues(e),s=e=>!!this._hhistBasedStudy||this._study.isPlotVisibleAt(e,2);for(const e of t)e.visible=e.visible&&s(e.id);return t}_createValuesProvider(e,t){return this._hhistBasedStudy?new n.HHistBasedValuesProvider(e,t):new r.StudyValuesProvider(e,t)}}class a extends i.StudyBaseWindowView{canShowItems(){const e=this._model.paneForSource(this._study);return!!e?.maximized().value()||this._model.panes().every((e=>!e.maximized().value()))}_createValuesProvider(e,t){return new o(e,t)}}},12965:(e,t,s)=>{s.d(t,{StudyStatusProvider:()=>n});var i=s(11542),r=(s(86252),s(35990));i.t(null,void 0,s(24077));class n extends r.StudyStatusProviderBase{sourceStatusText(){this._source.status();return super.sourceStatusText()}}},71320:(e,t,s)=>{s.d(t,{StudyValuesProvider:()=>v});var i=s(50335),r=s(49483),n=s(52859),o=s(37103),a=s(5471),l=s(11946),h=s(78861),c=s(4359),u=s(41425),d=s(63903),p=s(50151),_=s(53660),f=s(36313);const m=r.CheckMobile.any(),y=o.enabled("hide_last_na_study_output"),g=o.enabled("always_show_legend_values_on_mobile");class v{constructor(e,t,s,i=!0){this._emptyValues=[],this._colorProviders=new Map,this._study=e,this._model=t,this._searchNearestLeft=i,this._studyMetaInfo=this._study.metaInfo(),this._studyProperties=this._study.properties().childs(),this._isFundamental=!1;const r=this._studyMetaInfo.plots;if(!r)return;let n=0;r.forEach(((e,t)=>{if((0,c.isPlotWithTechnicalValues)(e))return;const i=e.id;this._emptyValues.push(function(e,t,s="",i=""){return{id:s,index:e,orderIndex:t,title:i,value:"",visible:!1}}(t,n++,i,s?"":this._study.guiPlotName(f.TitleDisplayTarget.StatusLine,i)));const r=(0,c.isOhlcPlot)(e)?e.target:i;this._colorProviders.set(r,(0,u.createStudyPlotColorProvider)(this._studyMetaInfo,this._study.properties(),r))}))}getItems(){return this._emptyValues}getPlotColor(e,t){const s=t[e+1];if(!(0,i.isNumber)(s))return"";const r=s>0;let n;const o=this._studyMetaInfo.plots[e];let a=o.id;const l=this._studyProperties;if((0,c.isOhlcPlot)(o))a=o.target||a,n=(0,p.ensureDefined)(l.ohlcPlots.childs()[a].childs().color).value();else if((0,c.isArrowsPlot)(o)){const e=(0,p.ensureDefined)(l.styles.childs()[a]);n=r?e.childs().colorup.value():e.childs().colordown.value()}else n=(0,p.ensureDefined)(l.styles.childs()[a]?.child("color")).value();let h=n;const u=this._colorProviders.get(a),d=u&&u.getPlotPointStyle(t);return d&&((0,c.isArrowsPlot)(o)?(r&&void 0!==d.colors[5]&&(h=d.colors[5]),r||void 0===d.colors[6]||(h=d.colors[6])):void 0!==d.colors[0]&&(h=d.colors[0])),"transparent"===h&&(h=n),h}getValues(e){const t=this._emptyValues.map((e=>({...e})));let s=null;const r=this._study.data().lastIndex(),o=this._studyProperties;if(null!==r){const e=this._searchNearestLeft?a.PlotRowSearchMode.NearestLeft:a.PlotRowSearchMode.Exact;for(const i of t){const t=o.styles.childs()[i.id]?.childs().display.value();if(0===t)continue ;const n=this._study.nearestIndex(r,e,i.index+1);if(void 0===n)continue;const a=n+this._study.offset(i.id);s=null!==s?Math.max(a,s):a}}(null===e||null!==s&&e>s)&&(e=s);const l=this._hideValues(),h=this._study.isVisible()&&!l?_.notAvailable:"";for(const e of t)e.value=h;if(l)return t;y&&t.length&&(t[t.length-1].value="");const u=this._study.priceScale();if(!this._study.isVisible()||null===e||null===u||u.isEmpty()||this._model.timeScale().isEmpty())return t;const f={};for(const s of t){const t=s.id,l=(0,d.getPriceValueFormatterForStudy)(this._study,t),h=(0,p.ensureDefined)(o.styles.childs()[t]),u=h.childs().display.value();if(s.visible=0!==u,!s.visible)continue;const _=h.hasChild("plottype")?h.child("plottype")?.value():null,m=this._searchNearestLeft&&this._isFundamental&&(_===c.LineStudyPlotStyle.StepLine||_===c.LineStudyPlotStyle.StepLineWithDiamonds),y=s.index,g=e-this._study.offset(t),v=m||null!==r&&g>r?a.PlotRowSearchMode.NearestLeft:a.PlotRowSearchMode.Exact,S=this._study.nearestIndex(g,v);if(void 0===S)continue;let b=f[t];if(void 0===b&&(b=this._study.getMinFirstBarIndexForPlot(t),Number.isFinite(b)&&(f[t]=b)),b>S)continue;const P=this._study.data().last(),w=this._study.data().valueAt(S)||(null!==P?P.value:null);if(null===w)continue;const I=w[y+1];(0,i.isNumber)(I)&&(s.value=l(I),s.color=(0,n.resetTransparency)(this.getPlotColor(y,w)))}return t}_hideValues(){return g?(0,l.isLineToolName)(h.tool.value())||null!==this._model.lineBeingEdited():m&&(null===this._model.crosshairSource().pane||(0,l.isLineToolName)(h.tool.value())||null!==this._model.lineBeingEdited())}}},11485:(e,t,s)=>{s.r(t),s.d(t,{StudiesChunkName:()=>Yt,Study:()=>us,emptyPrecalculatedAutoscaleInfo:()=>qt,studyFormatter:()=>hs});var i=s(50279),r=s(90054),n=s(16738),o=s(15943);const a=e=>e instanceof Date,l=e=>null!=e&&"object"==typeof e,h=(e,...t)=>Object.prototype.hasOwnProperty.call(e,...t),c=e=>l(e)&&(e=>0===Object.keys(e).length)(e),u=(e,t)=>{if(e===t)return{};if(!l(e)||!l(t))return t;const s=Object.keys(e).reduce(((e,s)=>(h(t,s)||(e[s]=void 0),e)),Object.create(null));return a(e)||a(t)?e.valueOf()==t.valueOf()?{}:t:Object.keys(t).reduce(((s,i)=>{if(!h(e,i))return s[i]=t[i],s;const r=u(e[i],t[i]);return!c(r)||a(r)||!c(e[i])&&c(t[i])?(s[i]=r,s):s}),s)},d=u;var p=s(50151),_=s(87465),f=s(9343),m=s(11542),y=s(12217),g=s(62312);function v(e){const{name:t,group:s}=e;return t.length>0?`${s?`${s}.`:""}${t}`:void 0}var S=s(10341),b=s(22613),P=s(62773),w=s(48096),I=s(52859),x=s(82130),C=s(29806),V=s(67135),M=(s(2088),s(24062)),T=s(72187),A=s(19844),R=s(45530),O=s(5471),D=s(18330),B=s(70954),N=s(40472),F=s(71320),k=s(63002);class E{constructor(e,t,s,i){this._study=e,this._model=t,this._showStudyValues=i??t.properties().childs().paneProperties.childs().legendProperties.childs().showStudyValues,this._hhistBasedStudy=void 0!==e.metaInfo().graphics.hhists,this._valuesProvider=this._createValuesProvider(e,t,s)}getItems(){return this._valuesProvider.getItems()}getValues(e){ const t=this._valuesProvider.getValues(e),s=this._study.properties(),i=this._showStudyValues.value()&&s.childs().showLegendValues.value(),r=e=>!!this._hhistBasedStudy||this._study.isPlotVisibleAt(e,8);for(const e of t)e.visible=e.visible&&i&&r(e.id);return t}_createValuesProvider(e,t,s){return this._hhistBasedStudy?new k.HHistBasedValuesProvider(e,t,s):new F.StudyValuesProvider(e,t,s)}}var L=s(4359);class H extends B.StudyBaseWindowView{constructor(e,t){super(e,t),this._showStudyValues=t.properties().childs().paneProperties.childs().legendProperties.childs().showStudyValues,this._showStudyValues.subscribe(this,(()=>this.update((0,N.sourceChangeEvent)(e.id()))));const s=this._study.properties();s.childs().showLegendValues.subscribe(this,(()=>this.update((0,N.sourceChangeEvent)(e.id()))));const i=this._study.metaInfo().plots,r=new Set;i.forEach((t=>{if((0,L.isOhlcPlot)(t)){const i=t.target;if(r.has(i))return;r.add(i),s.childs().ohlcPlots.childs()[i].childs().display.subscribe(this,(()=>this.update((0,N.sourceChangeEvent)(e.id()))))}else(0,L.isPlotSupportDisplay)(t)&&s.childs().styles.childs()[t.id]?.childs().display.subscribe(this,(()=>this.update((0,N.sourceChangeEvent)(e.id()))))}))}areValuesVisible(){return this._showStudyValues.value()}additional(){return null}destroy(){this._showStudyValues.unsubscribeAll(this);const e=this._study.properties();e.childs().showLegendValues.unsubscribeAll(this);const t=this._study.metaInfo().plots,s=new Set;t.forEach((t=>{if((0,L.isOhlcPlot)(t)){const i=t.target;if(s.has(i))return;s.add(i),e.childs().ohlcPlots.childs()[i].childs().display.unsubscribeAll(this)}else(0,L.isPlotSupportDisplay)(t)&&e.childs().styles.childs()[t.id]?.childs().display.unsubscribeAll(this)}))}_createValuesProvider(e,t){return new E(e,t)}}var W=s(78861),z=s(80671),U=s(60911),j=s(87163),G=s(98155),$=s(12965);class K{constructor(e,t,s){this._study=e,this._model=t,this._valuesProvider=new F.StudyValuesProvider(e,t,s)}getItems(){return this._valuesProvider.getItems()}getValues(e){const t=this._valuesProvider.getValues(e),s=e=>this._study.isPlotVisibleAt(e,8)||this._study.isPlotVisibleAt(e,1);for(const e of t)e.visible=e.visible&&s(e.id);return t}}var Y=s(36313),X=s(67455);function q(e,t){return e.studyId.localeCompare(t.studyId)}function J(e){const t=new Set,s=[];return e.forEach((e=>{t.has(e.studyId)||(t.add(e.studyId),s.push(e))})),s}function Z(e){const t=e.model().mainSeries();return{studyId:(0,p.ensureNotNull)(e.sourceId()),turnaround:e.turnaround(),sourceStudies:e.parentSources().filter((e=>e!==t)).map((e=>Z(e)))}}var Q=s(69422),ee=s(37103),te=s(94602),se=s(10307);class ie extends se.BitmapCoordinatesPaneRenderer{constructor(e){super(),this._data=e}hitTest(e){return null}_drawImpl(e){}_drawBackgroundImpl(e){const{context:t,horizontalPixelRatio:s,bitmapSize:i}=e,r=this._data;for(let e=0;e0?(s-=r,i+=r):(s+=r,i-=r);const n=this._study.getMinFirstBarIndexForPlot(this._plotName);if(n>i)return;s=Math.max(n,s);const o=this._study.data();for(const e of o.rangeIterator(s,i)){let s=e.index;const i=e.value;s+=r;const n={timePointIndex:Math.floor(s),left:NaN,center:NaN,right:NaN};let o=(0,_.isNumber)(t)?t:50;o=Math.min(o,100),o=Math.max(o,0);const a=this._colorProvider.getPlotPointStyle(i);void 0!==a.colors[1]&&(n.color=(0,I.generateColor)((0,p.ensureDefined)(a.colors[1]),o)),this._items.push(n)}this._model.timeScale().fillBarBorders(this._items)}}var ae,le=s(89323),he=s(45801),ce=s(51752),ue=s(77914),de=s(13173),pe=s(52746),_e=s(26705),fe=s(10555),me=s(6453),ye=s(50335),ge=s(50605),ve=s(2383),Se=s(45720),be=s(49251),Pe=s(27714),we=s(33350);!function(e){e.Left="left",e.Center="center",e.Right="right"}(ae||(ae={}));const Ie=(0,we.createDisconnectedCanvas)(document,(0,Pe.size)({width:0,height:0}),1);class xe{constructor(e,t,s,i,r,n="center",o=0){this._lines=e.split(/[^\S\r\n]*(?:\r\n|\r|\n)/),this._font=function(e,t,s,i){return(0,be.makeFont)(i,s,`${e?"bold ":""}${t?"italic ":""}`)}(t,s,i,r),this._fontSize=r,this._verticalPadding=~~(r/6),this._textAlign=n,this._lineSpacing=o;const a=(0,p.ensureNotNull)(Ie.getContext("2d"));a.font=this._font,a.textBaseline="top";let l=0;for(let e=0;e{for(const e of this._lines)o.strokeStyle&&s.strokeText(e,a,l),s.fillText(e,a,l),l+=this._fontSize,l+=this._lineSpacing})),s.restore()}}class Ce extends Se.AbstractMapContainer{constructor(e){super(),this._maxSize=e,this._keysQueue=[]}get(e){const{fontSize:t,text:s,align:i,font:r,bold:n,italic:o,lineSpacing:a=0}=e;if(!s||!t||!i)return null;const l=(0,be.makeFont)(t,r,o?"italic":"",n?"bold":""),h=(0,Se.getDefault3)(this._map,a,i,l,new Map);let c=h.get(s);return void 0!==c||(this._size>=this._maxSize?this._deleteFirstKey():++this._size,this._keysQueue.push([l,i,a,s]),c=new xe(s,n,o,r,t,i,a),h.set(s,c)),c}_deleteFirstKey(){const e=this._keysQueue.shift(),[t,s,i,r]=e,n=(0,p.ensureDefined)(this._map.get(i)),o=(0,p.ensureDefined)(n.get(s)),a=(0,p.ensureDefined)(o.get(t));a.delete(r),0===a.size&&o.delete(t),0===o.size&&n.delete(s),0===n.size&&this._map.delete(i)}}var Ve,Me=s(84617),Te=s(49483);!function(e){e.Transparent="rgba(0, 0, 0, 0)"}(Ve||(Ve={}));class Ae extends se.BitmapCoordinatesPaneRenderer{constructor(e,t={skipRenderingOptimizations:!1}){super(),this._items=[],this._barSpacing=0,this._vertOffset=0,this._textCache=t.textCache||new Ce(5e3),this._drawOperation=t.skipRenderingOptimizations?this._drawWithoutOptimizations.bind(this):this._drawWithOptimizations.bind(this),null!==e&&this.setData(e)}hitTest(e){const t=ve.HitTarget.Regular;let s=null;for(const i of this._items){if(!i)continue;const r=this._calcBoundingBox(i);if(r&&(0,me.pointInBox)(e,r)){const e={tooltip:this._getTooltip(i,r)};s=new ve.HitTestResult(t,e)}}return s}setData(e){if(this._height=void 0!==e.height?e.height:e.width,this._width=void 0!==e.width?e.width:e.height,this._color=e.color,this._borderColor=e.borderColor,this._vertOffset=e.vertOffset||0,e.text&&(this._text=e.text,this._fontSize=e.fontSize,this._lineSpacing=e.lineSpacing,this._textColor=e.textColor,this._textAlign=e.textAlign||"center"),void 0!==e.items&&void 0!==e.barSpacing){const t=e.visibleItemsRange?.startItemIndex??0,s=e.visibleItemsRange?.endItemIndex??e.items.length ;this.setItems(s>t?e.items.slice(t,s):[],e.barSpacing)}}setItems(e,t){this._setBaseData(e,t)}_drawImpl(e){this._preDrawInit(),this._drawOperation(e)}_calcBoundingBox(e){const t=e.vertOffset,s=this._getTextCache(e);if(!s)return;const i=s.textImageWidth,r=s.textImageHeight,n=i/2,o=e.y+t+e.textVertOffset,a=t>0?0:-r,l=t>0?r:0,h=new fe.Point(e.center-n,o+a),c=new fe.Point(e.center+n,o+l);return(0,fe.box)(h,c)}_unionBox(e,t){const s=Math.min(e.min.x,t.min.x),i=Math.max(e.max.x,t.max.x),r=Math.min(e.min.y,t.min.y),n=Math.max(e.max.y,t.max.y),o=new fe.Point(s,r),a=new fe.Point(i,n);return(0,fe.box)(o,a)}_getTooltip(e,t){if(e.tooltip)return{content:{type:"text",data:e.tooltip},tooltipDelay:200,extendMargin:!0,rect:{x:t.min.x,y:t.min.y,w:Math.abs(t.max.x-t.min.x),h:Math.abs(t.max.y-t.min.y)}}}_setBaseData(e,t){this._items.length=0,this._barSpacing=t;for(const t of e){if((0,ye.isNaN)(t.y))continue;const e=void 0===t.width?(0,p.ensureDefined)(this._width):t.width,s=void 0===t.height?(0,p.ensureDefined)(this._height):t.height,i=void 0===t.vertOffset?this._vertOffset:t.vertOffset,r=i>0?s:-s;this._items.push({width:e,height:s,vertOffset:i,textVertOffset:r,shapeWidth:0,shapeHeight:0,stepX:0,stepY:0,...t})}}_drawItemText(e,t){const s=this._getTextCache(t);if(null===s)return;const i=t.center,r=t.vertOffset,n=t.y+r+t.textVertOffset;let o;o=t.style&&void 0!==t.style.textColor?t.style.textColor:this._textColor;const a={style:{fillStyle:o},location:{x:i,y:n,horzAlign:ge.HorizontalAlign.Center,vertAlign:r>0?ge.VerticalAlign.Top:ge.VerticalAlign.Bottom}};s.paintTo(e,a)}_drawWithOptimizations(e){let t,s,i=null,r=!1;for(const n of this._items)(0,ye.isNaN)(n.y)||(n.style&&void 0!==n.style.color?(t=n.style.color||"rgba(0, 0, 0, 0)",s=n.style.borderColor||"rgba(0, 0, 0, 0)"):(t=this._color,s=this._borderColor),(i!==t||Te.isSafari)&&(i=t,r&&this._endPath(e),this._startPath(e,t,s)),this._drawItemShape(e,n),r=!0);r&&this._endPath(e);for(const t of this._items)(0,ye.isNaN)(t.y)||this._drawItemText(e,t)}_drawWithoutOptimizations(e){let t,s;for(const i of this._items){if((0,ye.isNaN)(i.y))continue;const r=(0,p.ensureDefined)(i.style);t=r.color||"rgba(0, 0, 0, 0)",s=r.borderColor||"rgba(0, 0, 0, 0)",this._startPath(e,t,s),this._drawItemShape(e,i),this._endPath(e),this._drawItemText(e,i)}}_drawItemShape(e,t){const{context:s,horizontalPixelRatio:i,verticalPixelRatio:r}=e;(0,we.drawScaled)(s,i,r,(()=>this._drawItemShapeUsingCSSPixels(s,t)))}_drawItemShapeUsingCSSPixels(e,t){}_preDrawInit(){}_startPath(e,t,s){}_endPath(e){}_getTextCache(e){const t=e.text||this._text,s=e.fontSize||this._fontSize,i=e.lineSpacing??this._lineSpacing,r=e.textAlign||this._textAlign,n=e.font??Me.CHART_FONT_FAMILY,o=e.bold??!1,a=e.italic??!1;return this._textCache.get({text:t,bold:o,italic:a,font:n,fontSize:s,lineSpacing:i,align:r})}}class Re extends Ae{_startPath(e,t,s){const i=e.context;i.beginPath(),i.lineWidth=this._lineWidth(e),i.lineCap="butt",i.strokeStyle=t}_endPath(e){e.context.stroke()}_lineWidth(e){return Math.max(1,Math.floor(2*e.horizontalPixelRatio))}} class Oe extends Ae{_startPath(e,t,s){const i=e.context;i.beginPath(),i.lineWidth=this._lineWidth(e),i.lineCap="butt",i.fillStyle=t,i.strokeStyle=s}_endPath(e){const t=e.context;t.fill(),t.stroke()}_lineWidth(e){return Math.max(1,Math.floor(e.horizontalPixelRatio))}}class De extends Oe{constructor(){super(...arguments),this._sign=0,this._thinArrow=!1,this._thinArrowLineWidth=0,this._headHeight=0,this._arrowWidth=0}setItems(e,t){this._setBaseData(e,t)}_drawItemShape(e,t){const{context:s,horizontalPixelRatio:i,verticalPixelRatio:r}=e,n=this._lineWidth(e)%2?.5:0,o=this._sign,a=this._arrowWidth,l=this._headHeight,h=Math.abs(t.height),c=Math.round(t.center*i)+n,u=t.vertOffset,d=Math.round((t.y+u+o*h/2)*r)+n,p=(0,ue.ceiledEven)(a*i),_=p/2,f=Math.round(h*r),m=Math.round(l*r);s.translate(c,d),this._thinArrow?(s.moveTo(0,0),s.lineTo(-_,-_*o),s.moveTo(0,0),s.lineTo(_,-_*o),s.moveTo(0,0),s.lineTo(0,-f*o),s.moveTo(-_,-f*o),s.lineTo(_,-f*o)):(s.moveTo(0,0),f=0?e.vertOffset:e.vertOffset-e.shapeHeight}}),He.set("PaneRendererLabelDown",class extends Ne{_calcBoundingBox(e){const t=e.center-e.shapeWidth/2,s=e.center+e.shapeWidth/2,i=e.y-e.shapeHeight+e.vertOffset,r=e.y+e.vertOffset,n=new fe.Point(t,i),o=new fe.Point(s,r);return(0,fe.box)(n,o)}_drawItemShape(e,t){const{context:s,horizontalPixelRatio:i,verticalPixelRatio:r}=e,n=this._lineWidth(e)%2?.5:0,o=Math.max(1,Math.floor(i))%2?.5:0,a=this._getArrowSize(t);let l=Math.round(a*i);(o+l)%1!=n%1&&(l+=.5);let h=Math.round(t.shapeWidth/2*i);(o+h)%1!=n%1&&(h+=.5);const c=Math.round(t.center*i)+o,u=Math.round((t.y+t.vertOffset)*r)+n,d=c+l,p=Math.round((t.y+t.vertOffset-a)*r)+n,_=c-l,f=c+h,m=Math.round((t.y+t.vertOffset-t.shapeHeight-a)*r)+n,y=c-h;s.moveTo(d,p),s.lineTo(c,u),s.lineTo(_,p),t.shapeWidth<=2*a?(s.lineTo(y,p),this._drawCorner(e,y,m,ke.leftUp),this._drawCorner(e,f,m,ke.rightUp),s.lineTo(f,p)):(this._drawCorner(e,y,p,ke.leftDown),this._drawCorner(e,y,m,ke.leftUp),this._drawCorner(e,f,m,ke.rightUp),this._drawCorner(e,f,p,ke.rightDown)),s.lineTo(d,p)}_getVerticalTextOffset(e){return-e.shapeHeight/2-this._getArrowSize(e)}_calcVertOffset(e){return Math.sign(e.vertOffset)<=0?e.vertOffset:e.vertOffset+e.shapeHeight}}),He.set("PaneRendererSquare",class extends Oe{_drawItemShape(e,t){const{context:s,horizontalPixelRatio:i,verticalPixelRatio:r}=e,n=Math.max(1,Math.floor(i))%2?.5:0,o=this._lineWidth(e)%2?.5:0;let a=Math.round(t.height/2*r);(n+a)%1!=o%1&&(a+=.5);const l=Math.round(t.center*i)+n,h=Math.round((t.y+t.vertOffset)*r)+n,c=l-a,u=h-a,d=l+a,p=h+a;s.rect(c,u,d-c,p-u)}_calcBoundingBox(e){ const t=e.height,s=Math.round(t/2),i=e.center-s,r=e.vertOffset,n=e.y+r-s,o=i,a=i+t,l=n,h=n+t,c=new fe.Point(o,l),u=new fe.Point(a,h);let d=(0,fe.box)(c,u);const p=super._calcBoundingBox(e);return p&&(d=this._unionBox(d,p)),d}}),He.set("PaneRendererTriangleApexUp",class extends Ee{_drawItemShape(e,t){const{context:s,horizontalPixelRatio:i,verticalPixelRatio:r}=e,n=t.width,o=t.height,a=Math.round(o/3),l=t.vertOffset-2*a,h=this._lineWidth(e)%2?.5:0,c=Math.max(1,Math.floor(i)),u=c%2?.5:0;let d=Math.round(n*i);d%2!=c%2&&(d+=1);const p=Math.round(t.center*i)+u,_=Math.round((t.y+l)*r),f=p+d/2,m=Math.round((t.y+l+o)*r)+h,y=p-d/2;s.moveTo(p,_),s.lineTo(f,m),s.lineTo(y,m),s.lineTo(p,_)}}),He.set("PaneRendererTriangleApexDown",class extends Ee{_drawItemShape(e,t){const{context:s,horizontalPixelRatio:i,verticalPixelRatio:r}=e,n=t.width,o=t.height,a=Math.round(o/3),l=t.vertOffset-a,h=this._lineWidth(e)%2?.5:0,c=Math.max(1,Math.floor(i)),u=c%2?.5:0;let d=Math.round(n*i);d%2!=c%2&&(d+=1);const p=Math.round(t.center*i)+u,_=Math.round((t.y+l)*r)+h,f=p+d/2,m=Math.round((t.y+l+o)*r),y=p-d/2;s.moveTo(y,_),s.lineTo(f,_),s.lineTo(p,m),s.lineTo(y,_)}}),He.set("PaneRendererXCross",class extends Re{_drawItemShapeUsingCSSPixels(e,t){const s=t.width,i=t.height,r=t.center-s/2,n=t.vertOffset,o=t.y-i/2+n;e.moveTo(r,o),e.lineTo(r+s,o+i),e.moveTo(r,o+i),e.lineTo(r+s,o)}_calcBoundingBox(e){const t=e.width,s=e.height,i=e.center-t/2,r=e.vertOffset,n=e.y-s/2+r,o=i,a=i+t,l=n,h=n+s,c=new fe.Point(o,l),u=new fe.Point(a,h);let d=(0,fe.box)(c,u);const p=super._calcBoundingBox(e);return p&&(d=this._unionBox(d,p)),d}});class We extends Le.StudyPaneViewInplaceUpdatable{constructor(e,t,s,i){super(t,s,i),this._renderer=null,this._shapesRenderer=null,this._selectionRenderer=null,this._isMarkersEnabled=ee.enabled("source_selection_markers"),this._study=e;const r=e.metaInfo().plots;for(let e=0;ethis._createItem(e,t??null,a,l,n)));let c=this._series.nearestIndex(i.firstBar(),O.PlotRowSearchMode.NearestRight),u=this._series.nearestIndex(i.lastBar(),O.PlotRowSearchMode.NearestLeft);if(void 0===c||void 0===u)return!1;n>0?(c-=n,u+=n):(c+=n,u-=n);const d=this._study.getMinFirstBarIndexForPlot(this._plotName);if(d>u)return!0;c=Math.max(d,c);const _=this._getTranspValue(),f=this._study.properties().childs().styles.childs()[this._plotName].childs(),m=f.color.value(),g=f.textColor?f.textColor.value():void 0,v=m,S=m,b=void 0===g?void 0:g,P=(0,p.ensureNotNull)(this._plotIndex),w=(0,_e.createEmptyStyle)(),I=h??(0,p.ensureNotNull)(r.firstIndex()),x=r.rangeIterator(I,(0,p.ensureNotNull)(r.lastIndex())+1);let C=(0,y.lowerbound)(this._items,I+n,((e,t)=>e.timePointIndex9?s-10:0;i.borderColor=(0,I.generateColor)(i.color,e)}void 0!==t.colors[2]&&(i.textColor=(0,I.generateColor)((0,p.ensureDefined)(t.colors[2]),s))}_updateRenderer(e,t){this._makeSureRendererIsValid();const s=this._model.timeScale(),i={},r=this._getTranspValue(),n=s.barSpacing(),o=this._calculateShapeHeight(n),a=this._study.properties().childs().styles.childs()[this._plotName].childs(),l=a.location.value(),h=this._calculateVerticalOffset(l,o+o/2);i.barSpacing=n,i.items=this._items,i.color=(0,I.generateColor)(a.color.value(),r),i.height=o,i.vertOffset=h,i.visibleItemsRange={startItemIndex:e,endItemIndex:t};const c=a.plottype.value(),u=ce.plotShapesData[c],d=new te.CompositeRenderer;u&&(this._shapesRenderer?this._shapesRenderer.setData(i):(this._shapesRenderer=this._createRenderer(u.paneRendererClass,i),d.append(this._shapesRenderer))),this._model.selection().isSelected(this._study)&&this._isMarkersEnabled&&null!==this._selectionData&&(this._selectionData.vertOffset=h,d.append(new he.SelectionRenderer(this._selectionData))),this._renderer=d}_createRenderer(e,t){const s=He.get(e);return new((0,p.ensureDefined)(s))(t)}_getSeriesVal(e,t){const s=(0,pe.barFunction)(e),i=this._series.data().valueAt(t);return null===i?null:s(i)}_getTranspValue(){let e=0;const t=this._study.properties().childs();t.transparency&&(e=t.transparency.value(),e=(0,_.isNumber)(e)?e:50);const s=t.styles.childs()[this._plotName].childs();return s.transparency&&(e=s.transparency.value(),e=(0,_.isNumber)(e)?e:50),(0,ue.clamp)(e,0,100)}_createItem(e,t,s,i,r){const n=this._study.properties().childs().styles.childs()[this._plotName].childs().location.value(),o={origPrices:{price:NaN},timePointIndex:e+r} ;if((null===t||0===t)&&n!==D.MarkLocation.Absolute)return o;if(null==t)return o;let a=NaN;switch(n){case D.MarkLocation.AboveBar:{const t=this._getLocationPrice(e,s,r);if(null===t)return o;a=t;break}case D.MarkLocation.BelowBar:{const t=this._getLocationPrice(e,i,r);if(null===t)return o;a=t;break}case D.MarkLocation.Absolute:a=(0,p.ensureNotNull)(t);break;case D.MarkLocation.Top:case D.MarkLocation.Bottom:a=0;break;default:throw new Error("Bad value: "+n)}return{y:NaN,origPrices:{price:a},timePointIndex:e+r}}_dependsOnSeriesData(){const e=this._study.properties().childs().styles.childs()[this._plotName].childs().location.value();return e===D.MarkLocation.AboveBar||e===D.MarkLocation.BelowBar}_getValueForUpdating(e){const t=e.value[this._plotIndex+1];if(null==t)return null;const s=this._study.properties().childs().styles.childs()[this._plotName].childs().location.value();if(0===t&&s!==D.MarkLocation.Absolute)return null;const i=this._study.offset(this._plotName),{hiPlot:r,loPlot:n}=this._hiLoPlots();switch(s){case D.MarkLocation.AboveBar:return this._getLocationPrice(e.index,r,i);case D.MarkLocation.BelowBar:return this._getLocationPrice(e.index,n,i)}return super._getValueForUpdating(e)}_convertItemsToCoordinates(e,t,s,i){for(let e=s;e{for(let t=s;t0&&(s=t),s}_hiLoPlots(){let e,t;let s=null;switch(this._series.properties().childs().style.value()){case 2:s="lineStyle";break;case 14:s="lineWithMarkersStyle";break;case 15:s="steplineStyle";break;case 3:s="areaStyle"}return s?(e=this._series.properties().childs()[s].childs().priceSource.value(),t=e):(e="high",t="low"),{hiPlot:e,loPlot:t}}_getLocationPrice(e,t,s){const i=Math.min(e+s,(0,p.ensureNotNull)(this._series.data().last()).index);return this._getSeriesVal(t,i)}}class ze extends We{_updateRenderer(e,t){const s=this._study.properties().childs().styles.childs()[this._plotName].childs(),i=this._model.timeScale(),r={},n=this._getTranspValue(),o=i.barSpacing();let a ;a=this._plotStyleInfo.size?this._calculateShapeHeight(25,this._plotStyleInfo.size):Math.round(o/2),a=Math.max(a,1);const l=s.location.value(),h=(0,I.generateColor)(s.color.value(),n),c=n>19?n-10:0,u=this._calculateVerticalOffset(l,Math.round(1.5*a));r.barSpacing=o,r.items=this.items(),r.color=h,r.borderColor=(0,I.generateColor)(s.color.value(),c),r.height=a,r.vertOffset=u,r.visibleItemsRange={startItemIndex:e,endItemIndex:t};const d=s.plottype.value(),p=ce.plotShapesData[d],_=this._plotStyleInfo.text;if(void 0!==_&&""!==_.trim()){let e=_.replace(/\\n/gm,"\n");e=(0,le.cleanButAmpersand)(e,!0),r.text=e,r.fontSize=12;const t=s.textColor?s.textColor.value():void 0;r.textColor=t?(0,I.generateColor)(t,n):h}if(this._renderer&&this._shapesRenderer&&this._selectionRenderer)this._shapesRenderer.setData(r),this._model.selection().isSelected(this._study)&&this._isMarkersEnabled&&null!==this._selectionData?(this._selectionData.vertOffset=u,this._selectionRenderer.setData(this._selectionData)):this._selectionRenderer.setData(null);else{const e=new te.CompositeRenderer;this._shapesRenderer=super._createRenderer(p.paneRendererClass,r),e.append(this._shapesRenderer),this._selectionRenderer=new he.SelectionRenderer(this._selectionData??void 0),this._model.selection().isSelected(this._study)&&this._isMarkersEnabled&&null!==this._selectionData?this._selectionData.vertOffset=u:this._selectionRenderer.setData(null),e.append(this._selectionRenderer),this._renderer=e}}}var Ue,je=s(87795),Ge=s.n(je),$e=s(4539),Ke=s(57658);!function(e){e[e.SimplifiedPaintingMaxFontSize=4]="SimplifiedPaintingMaxFontSize"}(Ue||(Ue={}));class Ye extends Ae{constructor(e,t){super(null,t),this._textWidthCache=new Ke.TextWidthCache,this._fontSizeEnsured=0,this._font="",this._ch="",null!==e&&this.setData(e)}setData(e){super.setData(e),this._fontSizeEnsured=(0,p.ensureDefined)(this._height),this._font=(0,be.makeFont)(this._fontSizeEnsured,e.fontFamily||Me.CHART_FONT_FAMILY);const t=e.char.slice(0,40);this._ch=Ge()(t)[0]||" "}hitTest(e){const t=(0,$e.interactionTolerance)().series+this._fontSizeEnsured/2;for(const s of this._items){if(new fe.Point(s.center,s.y+s.vertOffset).subtract(e).length()<=t)return new ve.HitTestResult(ve.HitTarget.Regular)}return null}_drawItemShape(e,t){const s=t.center,i=t.vertOffset>0?1:-1,r=Math.trunc(this._fontSizeEnsured/6),n=t.y+t.vertOffset-i*Math.round(this._fontSizeEnsured/2)+(i>0?r:-this._fontSizeEnsured);let o;o=t.style&&void 0!==t.style.color?t.style.color:this._color;const{context:a,horizontalPixelRatio:l,verticalPixelRatio:h}=e;a.font!==this._font&&(a.font=this._font);const c=this._textWidthCache.measureText(a,this._ch);if(this._fontSizeEnsured<=4/l){a.save();const e=Math.max(1,Math.floor(l));let i=Math.max(1,Math.floor(c*l));i%2!=e%2&&(i+=i>1?-1:1);const r=Math.round(n*h)+(t.vertOffset>=0?0:-i);return a.fillStyle=o,a.fillRect(Math.round(s*l)+(l%2?.5:0)-i/2,r,i,i),void a.restore()}(0,we.drawScaled)(a,l,h,(()=>{a.fillStyle=o,a.textAlign="center",a.textBaseline="top",a.fillText(this._ch,s,n)}))}_startPath(e,t,s){}_endPath(e){}} class Xe extends We{constructor(){super(...arguments),this._charRenderer=new Ye(null)}_updateRenderer(e,t){const s=this._getTranspValue(),i=this._model.timeScale().barSpacing();let r;const n=this._study.properties().childs().styles.childs()[this._plotName].childs();r=this._plotStyleInfo.size?this._calculateShapeHeight(50,this._plotStyleInfo.size):Math.round(i);const o=n.location.value(),a=(0,I.generateColor)(n.color.value(),s),l=this._calculateVerticalOffset(o,r),h={items:this.items(),barSpacing:i,char:(0,p.ensureDefined)(n.char?.value()??this._plotStyleInfo.char),height:r,vertOffset:l,color:a,visibleItemsRange:{startItemIndex:e,endItemIndex:t}},c=this._plotStyleInfo.text;if(void 0!==c&&""!==c.trim()){let e=c.replace(/\\n/gm,"\n");e=(0,le.cleanButAmpersand)(e,!0),h.text=e,h.fontSize=12;const t=n.textColor?n.textColor.value():void 0;h.textColor=t?(0,I.generateColor)(t,s):a}this._charRenderer.setData(h);const u=new te.CompositeRenderer;u.append(this._charRenderer),this._model.selection().isSelected(this._study)&&this._isMarkersEnabled&&null!==this._selectionData&&(this._selectionData.vertOffset=l,u.append(new he.SelectionRenderer(this._selectionData))),this._renderer=u}}var qe=s(24377);class Je{constructor(e,t,s,i,r){this.left=NaN,this.right=NaN,this.height=NaN,this.center=e,this.y=t,this.origHeight=s,this.isUp=i,this.origPrices=r,this.timePointIndex=e,this.style={}}}function Ze(e){return Math.round(e/4)}function Qe(e){return Math.round(e/2)}class et extends se.BitmapCoordinatesPaneRenderer{constructor(e){super(),this._data=e}hitTest(e){const t=this._data,s=Qe(t.barSpacing),i=Math.round(s/2),r=Math.round(s),n=Ze(t.barSpacing),o=t.visibleItemsRange?.startItemIndex??0,a=t.visibleItemsRange?.endItemIndex??t.items.length;if(o>=a)return null;for(const s of t.items.slice(o,a)){if(!s)continue;if(!Number.isFinite(s.center)||!Number.isFinite(s.y))continue;const t=Math.abs(s.height),o=s.isUp?-1:1,a=t+r,l=s.y-o*n,h=l-o*a,c=s.center-i,u=s.center+i;if(c=_))for(const e of r.items.slice(p,_)){if(!Number.isFinite(e.center)||!Number.isFinite(e.y))continue;const n=e.isUp?-1:1,p=Math.round(Math.abs(e.height)*s),_=Math.round(e.center*t)+d,f=Math.round((e.y-n*o)*s)+d;i.beginPath(),i.translate(_,f);const m=(e.style&&e.style.color)??(e.isUp?r.colorup:r.colordown);a?(i.moveTo(0,0),i.lineTo(-c,-c*n),i.moveTo(0,0),i.lineTo(c,-c*n),i.moveTo(0,0),i.lineTo(0,-p*n),i.moveTo(-c,-p*n),i.lineTo(c,-p*n),i.lineWidth=l,i.strokeStyle=m,i.stroke()):(i.moveTo(0,0),p0,{hiPlot:r,loPlot:n}=this._hiLoPlots(),o=this._study.offset(this._plotName),a=Math.min(s+o,(0,p.ensureNotNull)(this._series.data().last()).index);if(i){const e=this._getSeriesVal(n,a);if(null!==e)return e}else{const e=this._getSeriesVal(r,a);if(null!==e)return e}return null}_updateItem(e,t){const s=this._getValueForUpdating(e),i=e.value[this._plotIndex+1]>0;return this._items[t].origPrices.price=s??NaN,this._items[t].isUp=i,t+1}_createItem(e,t,s,i,r){const n={center:NaN,y:NaN,origPrices:{price:NaN,timePointIndex:NaN},origHeight:NaN,timePointIndex:e+r};if(!t)return n;const o=Math.min(e+r,(0,p.ensureNotNull)(this._series.data().last()).index),a=t>0;let l;if(a){const e=this._getSeriesVal(i,o);if(null===e)return n;l=e}else{const e=this._getSeriesVal(s,o);if(null===e)return n;l=e}return new Je(e+r,l,t,a,{price:l,timePointIndex:e+r})}_dependsOnSeriesData(){return!0}_convertItemsToCoordinates(e,t,s,i){this._convertItemsToCoordinatesImpl(e,t,s,i)}_createSelectionDataPoint(e,t,s,i){const r=this._model.timeScale().barSpacing(),n=Ze(r),o=function(e){return Qe(e)}(r),a=super._createSelectionDataPoint(e,t,s,i),l=this._items[(0,y.lowerbound)(this._items,t,((e,t)=>e.timePointIndexi){const e=s;s=i,i=e}const r=this._items,n=e.visibleItemsRange?.startItemIndex??0,o=(e.visibleItemsRange?.endItemIndex??r.length)-1;let a=0;for(let e=n;e<=o;e++){const t=r[e],s=Math.abs(t.origHeight);s>a&&(a=s)}const l=(i-s)/a;for(let e=n;e<=o;e++){const t=r[e],i=Math.abs(t.origHeight);t.height=i*l+s}}}var st=s(64138);class it extends ne.StudyForceOverlayPlotView{constructor(e,t,s,i){super(t,s,i),this._bars=[],this._invalidated=!1,this._isMarkersEnabled=ee.enabled("source_selection_markers"),this._selectionData=null,this._ohlcPlotIndexes=new Map,this._study=e,this._isMarkersEnabled=ee.enabled("source_selection_markers"),this._colorProvider=(0,re.createStudyPlotColorProvider)(e.metaInfo(),e.properties(),i),this._selectionIndexer=new de.SelectionIndexes(s.timeScale());const r=this._study.metaInfo().plots;for(let e=0;ei)return;s=Math.max(r,s);const n=this._study.data(),o=this._study.firstValue(void 0,this.isForceOverlay());if(null===o)return;const a=n.rangeIterator(s,i),l=(0,p.ensureDefined)(this._study.properties().childs().ohlcPlots).childs()[this._plotName].childs(),h=new Map,c=(e,t)=>{const s=e+"@"+t;if(!h.has(s)){const i=(0,I.generateColor)(e,t);return h.set(s,i),i}return h.get(s)},u=(0,_e.createEmptyStyle)();for(const e of a){let t=e.index;const s=e.value;t=Math.floor(t);let i=!0;const r=new Map;for(let e=1;e<=4;++e){const t=this._ohlcPlotIndexes.get(e);if(void 0===t){i=!1;break}const n=s[t+1];if(null==n){i=!1;break}r.set(e,n)}if(!i)continue;const n=(0,p.ensureDefined)(r.get(1)),o=(0,p.ensureDefined)(r.get(4)),a=(0,p.ensureDefined)(r.get(2)),h=(0,p.ensureDefined)(r.get(3)),d=Math.max(n,a,h,o),_=Math.min(n,a,h,o);let f=(0,p.ensureDefined)(c(l.color.value(),0));const m=this._colorProvider.getPlotPointStyle(s,u);void 0!==m.colors[0]&&(f=(0,p.ensureDefined)(m.colors[0]));const y={open:n,high:d,low:_,close:o,color:f,wickColor:m.colors[4],borderColor:m.colors[3],hollow:null,center:NaN,left:NaN,right:NaN,timePointIndex:Math.round(t)};this._bars.push(y)} if(e.barPricesToCoordinates(this._bars,o),this._model.timeScale().fillBarBorders(this._bars),this._model.selection().isSelected(this._study)){const t=this._selectionIndexer.indexes();this._selectionData={points:[],hittestResult:ve.HitTarget.Regular,bgColors:[],visible:!0,barSpacing:this._model.timeScale().barSpacing()};const s=(0,p.ensureNotNull)(this._model.paneForSource(this._study)).height(),i=(0,p.ensureDefined)(this._ohlcPlotIndexes.get(4));for(let r=0;rthis._colorPlotIndex=this._colorPlotIndex??{type:1};for(let t=0;t{null===this._bandAKey&&s.id===e&&(this._bandAKey=i),null===this._bandBKey&&s.id===t&&(this._bandBKey=i)}))}}var xt=s(86252),Ct=s(81922),Vt=s(51304),Mt=s(48943),Tt=s(95059),At=s(91106),Rt=s(63670),Ot=s(30693),Dt=s(28477);class Bt extends Dt.AbstractBarColorer{constructor(e,t){super(),this._rgbaFromInteger=(0,pt.rgbaFromIntegerCached)(),this._study=e, this._plotIndex=t}applyBarStyle(e,t,s,i){if(t)return s;const r=this._study.properties().childs();if(!r.visible.value())return s;const n=this._study.metaInfo(),o=this._study.data();if(!o||0===o.size())return s;const a=n.plots[this._plotIndex],l=this._getOffset();if(this._study.getMinFirstBarIndexForPlot(a.id)>e+l)return s;if(0===r.styles.childs()[a.id].childs().display.value())return s;const h=o.valueAt(e-l);if(null===h)return s;let c=h[this._plotIndex+1];if(null==c)return s;if(c=Math.round(c),n.isRGB)s.barColor=this._rgbaFromInteger(c),s.upColor=s.barColor,s.downColor=s.barColor;else{const e=n.plots[this._plotIndex];if("palette"in e){const t=e.palette,i=r.palettes.childs()[t],o=(0,p.ensureDefined)(n.palettes?.[t]),a=o.valToIndex?(0,p.ensureDefined)(o.valToIndex[c]):c,l=i.childs().colors.childs()[a].childs().color.value();s.barColor=l,s.upColor=l,s.downColor=l}}return s}firstColoredBar(e){let t=e;for(const s of this._backColorers)t=Math.min(t,s.firstColoredBar(e)??1/0);const s=this._getOffset();t=Math.min(t,e+s);const i=this._getBars().firstIndex(),r=Math.max(t,i??-1/0),n=this._study.metaInfo().plots[this._plotIndex];return Math.max(this._study.getMinFirstBarIndexForPlot(n.id),r)}_getBars(){return this._study.series().bars()}_getOffset(){const e=this._study.metaInfo().plots[this._plotIndex];return this._study.offset(e.id)}}var Nt=s(76422),Ft=s(67563),kt=s(64717);class Et extends at.PanePriceAxisView{constructor(e,t,s,i){super(e,t,s),this._dataSource=t,this._isForceOverlay=t.metaInfo().isPlotForceOverlay(i)}_position(){const e=this._isForceOverlay?this._chartModel.mainPane():this._chartModel.paneForSource(this._dataSource);if(null===e)return null;const t=this._isForceOverlay?this._chartModel.mainSeries().priceScale():this._dataSource.priceScale();if(null===t)return null;let s=e.priceScalePosition(t);return"overlay"===s&&(s=e.priceScalePosition(e.defaultPriceScale())),"overlay"===s?null:s}}var Lt=s(56265);class Ht{constructor(e,t){this._study=e,this._valuesProvider=new F.StudyValuesProvider(e,t,!1,!1)}getItems(){const e=this._study.properties().childs(),t=this._valuesProvider.getItems();for(const s of t){const t=s.id,i=(0,p.ensureDefined)(e.styles.childs()[t]).childs().display.value();s.visible=0!==i}return t}getValues(e){const t=this._valuesProvider.getValues(e),s=this._study.plots().lastIndex(),i=this._study.plots().firstIndex();if(null===s||null===i)return null;for(const r of t){const t=e-this._study.offset(r.id);(t>s||t((0,L.isColorerPlot)(e)||(0,L.isDataPlot)(e))&&e.target===t))}function os(e,t,s){let i=0,r=0;return Math.sign(r)-Math.sign(i)}function as(e){const t=(0,Mt.combine)((e=>e.map((e=>as(e.parentSourcesVW().weakReference())))),e);return(0,Mt.accumulate)(((e,t)=>Array.from(new Set(t.concat(e.flat(20))))),t.ownership(),e).ownership()}function ls(e){return"inherit"===e.type&&(e.type="price"),e}function hs(e,t,s,i){{const t=(0,_.isNumber)(i)?i:void 0,r=jt.customFormatters?.studyFormatterFactory?.(e,s,t)??null;if(null!==r)return r}if(null!==t)switch(e.type){case"inherit":case"price":return new Ft.PriceFormatter({priceScale:t});case"volume":return(0,Lt.getVolumeFormatter)(Math.log10(t));case"percent":return(0,Lt.getPercentageFormatter)(Math.log10(t))}if("inherit"===e.type)return null;const r=(0,_.isNumber)(e.precision)?Math.pow(10,e.precision):void 0;switch(e.type){case"price":return new Ft.PriceFormatter({priceScale:r});case"volume":{let t=e.precision;return void 0===t&&(t=s&&(0,_.isNumber)(s.volume_precision)?s.volume_precision:0),(0,Lt.getVolumeFormatter)(t)}case"percent":return(0,Lt.getPercentageFormatter)(void 0===r?void 0:Math.log10(r));default:return Gt.logWarn(`Unsupported format type: ${e.type}`),null}}const cs=new Set(["first_visible_bar_time","last_visible_bar_time","subscribeRealtime"]);class us extends V.PriceDataSource{constructor(e,t,s,i,r,n,o){super(e),this._onStart=new w.Delegate,this._restarting=!1,this._paneViews=[],this._forceOverlaysPaneViews=[],this._legendView=null,this._floatingTooltipView=null,this._priceAxisViews=[],this._forceOverlayPriceAxisViews=[],this._priceAxisViewsBase=[],this._resolvedSymbols={},this._resolvedSymbolsByInput={},this._priceLinesAxisViews=[],this._labelPaneViews=[],this._forceOverlayLabelPaneViews=[],this._ownFirstValue=null,this._formatter=null,this._defaultFormatter=null,this._dataUpdated=new w.Delegate,this._currencySourceSymbolInputProperty=null, this._pineSourceCodeModel=null,this._alertSourceModel=null,this._onHibernationStateChange=new w.Delegate,this._symbolsResolved=new w.Delegate,this._statusChanged=new w.Delegate,this._inputsAnchorsPaneView=null,this._inputsLinesPaneView=null,this._inputsTimeAxisPaneViews=[],this._inputsPriceAxisPaneViews=[],this._sources=new P.WatchedObject([],y.compareTwoCollectionsByIds),this._status=new b.WatchedValue({type:xt.StudyStatusType.Undefined}),this._compileActiveStatus=new P.WatchedObject(null),this._compileErrorStatus=new P.WatchedObject(null),this._wasCompletedBefore=!1,this._isStarted=!1,this._isSubscribedToSessionId=!1,this._titleStrCache={},this._titleInPartsCache={},this._inputsInPartsCache={},this._children=[],this._graphicsPriceAxisViews=[],this._serverPlotOffsets=new P.WatchedObject({}),this._ongoingDataUpdate=Promise.resolve(),this._studyModified=!1,this._tagsChanged=new w.Delegate,this._turnaround="st0",this._pendingResolveSymbols=new Map,this._onIsActualIntervalChange=new w.Delegate,this._childStudyByRebind=new w.Delegate,this._lastNonEmptyPlotRowCache={},this._startMovingPoint=null,this._processHibernateBound=this.processHibernate.bind(this,1),this._maxOffset=new b.WatchedValue(0),this._currencySourceSymbolInfo=null,this._graphicsPriceRangeGroups=null,this._graphicsViewsReady=!1,this._visibleTimeRangeInputs=null,this._turnaroundCounter=0,this._deferredPinePatchProps=!1,this._propertiesPatched=Promise.resolve(),this._resetPropertiesPatched=Promise.resolve(),this._abortPatchPropsController=new AbortController,this._abortResetPatchPropsController=new AbortController,this._aboutToBeDestroyed=new w.Delegate,this._definitionsViewModel=null,this._plotFormatters=new Map,this._showPineVersionInStatusLine=new b.WatchedValue(!1).spawn(),this._onParentSourcesChanges=new w.Delegate,this._statusChangesSubscriber={},this._calculationTime=new b.WatchedValue(0),this._stateForAlertCache=null,this._idForAlertCache=null,this._idForAlertWV=new b.WatchedValue(""),this._chartApi=e.chartApi(),this._properties=t,this._originalMetaInfo=r,this._metaInfo=new b.WatchedValue(i),this._studyName=(0,Mt.combine)((e=>e.useVersionFromMetaInfo?(0,A.getStudyIdWithVersion)(e):this._getStudyIdWithLatestVersion()),this._metaInfo.weakReference()),this._hideMatches=i.inputs.filter((e=>e.hideWhenPlotsHidden)).map((e=>({id:e.id,plotIds:e.hideWhenPlotsHidden||[]}))),this._series=this._model.mainSeries(),this._series.onIntervalChanged().subscribe(this,this._calcIsActualInterval),this._series.alertCreationAvailable().subscribe(this._updateAlertCreationAvailable.bind(this)),this._showStudyArgumentsProperty=(0,X.combineProperty)(((e,t)=>e&&t),e.properties().childs().paneProperties.childs().legendProperties.childs().showStudyArguments.weakReference(),this._properties.childs().showLegendInputs.weakReference()),this._model.symbolAliasService()?.onAliasChanged().subscribe(this,(()=>{this._onFormatterPropsChanged(),this.invalidateTitleCache()})),e.collapsed().subscribe(this._processHibernateBound),this._sources.setValue(s), A.StudyMetaInfo.setChildStudyMetaInfoPropertiesSourceId(i,s[0]?.id(),t),s.forEach((e=>{e.setChild(this)})),[this._series,...s].forEach((e=>{e.currencyChanged().subscribe(this,this._onSourceCurrencyChanged),e.unitChanged().subscribe(this,this._onSourceUnitChanged),e.priceRangeReadyChanged().subscribe(this,this._onSourcePriceRangeReadyChanged),e.formatterChanged().subscribe(this,this._onSourceFormatterChanged),e.priceStepChanged().subscribe(this,this._onSourcePriceStepChanged)})),Zt&&this._model.mainSeries().properties().childs().statusViewStyle.childs().symbolTextSource.subscribe(this,(()=>{this.invalidateTitleCache(!0)}));const a=this._properties.childs();for(const e of A.StudyMetaInfo.getSourceInputIds(i))a.inputs.childs()[e]?.subscribe(this,this._onSourceInputChanged);this._plotOffsets=(0,Mt.combine)(((e,t,s,i)=>(i.plots??[]).reduce(((i,r)=>{const n=r.id,o=(e[n]??0)+(s?.childs()[n]?.childs().val.value()??0)+(t?.childs().val.value()??0);return i[n]=o,i}),{})),this._serverPlotOffsets.weakReference(),(0,X.createWVFromGetterAndSubscription)((()=>this.properties().childs().offset),this.properties().childs().offset??new w.Delegate).ownership(),(0,X.createWVFromGetterAndSubscription)((()=>this.properties().childs().offsets),this.properties().childs().offsets??new w.Delegate).ownership(),this._metaInfo.weakReference()),this._properties.subscribe(this,this._onPropertiesChanged),a.visible.subscribe(this,this._visibleChanged),a.visible.subscribe(this,(()=>this.processHibernate())),a.intervalsVisibilities.subscribe(this,this._calcIsActualInterval),a.inputs.subscribe(this,this._updateMaxOffsetValue),void 0!==a.offsets&&a.offsets.subscribe(this,this._updateMaxOffsetValue),void 0!==a.offset&&a.offset.subscribe(this,this._updateMaxOffsetValue),this._initializeCurrencySource(),W.hideAllIndicators().subscribe(this,this._visibleChanged);for(let e=0;e{this.processHibernate(),this.invalidateTitleCache(),n&&this._series.invalidateBarColorerCache()}))}for(const e of Object.keys(i.graphics))for(const t of Object.keys(i.graphics[e])){const s=a.graphics.childs()[e]?.childs()[t];s&&s.childs().visible&&(0,p.ensureDefined)(s.childs().visible).subscribe(this,(()=>this.processHibernate()))}this._isActualInterval=(0,Ct.isActualInterval)(this._series.intervalObj().value(),a.intervalsVisibilities),this._initializeStudyInputsPaneViews(),this._handler=e=>this._onData(e),this._valuesProvider=new F.StudyValuesProvider(this,e),this._tableViewValuesProvider=new Ht(this,e),this._graphics=new R.LiveStudyGraphics(i.graphics),this._chartApi=e.chartApi(),this._invalidateLastNonEmptyPlotRowCache(),this._data=new T.PlotList((0,kt.studyPlotFunctionMap)(i),kt.studyEmptyPlotValuePredicate),this._createViews(),this._recreatePriceFormattingDependencies(this._series.symbolInfo()),a.precision.subscribe(this,this._onFormatterPropsChanged), this._metaInfo.subscribe((()=>this._onFormatterPropsChanged())),this._showStudyArgumentsProperty.subscribe(this,(()=>this.invalidateTitleCache(!0))),a.inputs.subscribe(this,(()=>this.invalidateTitleCache(!0))),ee.enabled("update_study_formatter_on_symbol_resolve")&&e.mainSeries().dataEvents().symbolResolved().subscribe(this,this._recreatePriceFormattingDependencies),e.mainSeries().dataEvents().symbolResolved().subscribe(this,(()=>this.invalidateTitleCache(!0)));const l=new Set;if(this._simplePlotsCount=i.plots.filter(((e,t)=>{if((0,L.isLinePlot)(e))return!0;if((0,L.isOhlcPlot)(e)){const t=e.target;return!l.has(t)&&(l.add(t),!0)}return!1})).length,this.hasBarColorer()&&a.visible.subscribe(this,(()=>e.mainSeries().invalidateBarStylesCache)),this._definitionsViewModel=null,this._updateMaxOffsetValue(),i.inputs.some((e=>cs.has(e.id)))){this._visibleTimeRangeInputs=e.visibleRangeStudiesInputs().spawn();const t=this._visibleTimeRangeInputs.value();let s=null!==t;this._visibleTimeRangeInputs.subscribe((e=>{const t=()=>{this._onVisibleTimeRangeInputsChanged(e),s!==(null!==e)&&(s=null!==e,!s||this._restarting||this.isStarted()||this.start(!0))};this._statusChanged.unsubscribeAll(this._statusChangesSubscriber),this._status.value().type===xt.StudyStatusType.Loading?this._statusChanged.subscribe(this._statusChangesSubscriber,t,!0):t()})),t&&this._updateVisibleTimeRangeInputs(t,!1)}this._properties.setNameInOwner((0,Wt.propertyPathForSource)(this)),o&&this._pinePatchProps();const h=as(this.parentSourcesVW().weakReference());this._allOwnerSources=(0,Mt.combine)(((e,t)=>{const s=[];for(;null!==t;)s.push(t),t=t.ownerSource();return s}),h,(0,X.createWVFromGetterAndSubscription)((()=>this.ownerSource()),this.ownerSourceChanged()).ownership()),this._symbolSource=(0,Mt.combine)((e=>this._firstSourceOrSeries().symbolSource()),this._allOwnerSources.weakReference())}destroy(){this._signlePerformanceValue?.destroy(),this._aboutToBeDestroyed.fire(),null!==this._definitionsViewModel&&(this._definitionsViewModel.destroy(),this._definitionsViewModel=null),this._showStudyArgumentsProperty.unsubscribeAll(this),this._model.mainSeries().dataEvents().symbolResolved().unsubscribeAll(this),this._model.symbolAliasService()?.onAliasChanged().unsubscribeAll(this);this.parentSources().forEach((e=>{e.currencyChanged().unsubscribeAll(this),e.unitChanged().unsubscribeAll(this),e.priceRangeReadyChanged().unsubscribeAll(this),e.formatterChanged().unsubscribeAll(this),e.priceStepChanged().unsubscribeAll(this)})),this._series.properties().childs().statusViewStyle.childs().symbolTextSource.unsubscribeAll(this),this._series.onIntervalChanged().unsubscribeAll(this),this._series.alertCreationAvailable().unsubscribe(this._updateAlertCreationAvailable),this.formatterChanged().unsubscribe(this,this.invalidateTitleCache),W.hideAllIndicators().unsubscribe(this,this._visibleChanged),this._model.collapsed().unsubscribe(this._processHibernateBound),null!==this._currencySourceSymbolInputProperty&&this._currencySourceSymbolInputProperty.unsubscribeAll(this), this._legendView?.destroy(),this._floatingTooltipView?.destroy(),this._pineSourceCodeModel?.get()?.destroy(),this._visibleTimeRangeInputs?.destroy(),this._showPineVersionInStatusLine.destroy(),this._alertStateVersion?.destroy(),this._metaInfo.destroy(),this._studyName.destroy(),this._allOwnerSources.destroy(),this._sources.destroy(),this._symbolSource.destroy(),this._status.destroy(),this._compileActiveStatus.destroy(),this._compileErrorStatus.destroy(),this._plotOffsets.destroy(),this._serverPlotOffsets.destroy(),this._properties.destroy(),super.destroy()}setId(e){super.setId(e),this._properties.setNameInOwner((0,Wt.propertyPathForSource)(this))}properties(){return this._properties}propertiesPatched(){return this._propertiesPatched}isDraggable(){return!this._metaInfo.value().linkedToSeries}logs(){return null}logLevelMask(){const e=this._properties.childs().inputs.childs().__log_level.value();if(!(0,_.isNumber)(e)||e<0||e>7)throw new Error(`Value of log level is unexpected, current value is ${e}, but expected values from 0 to 7`);return{error:Boolean(1&e),warning:Boolean(2&e),info:Boolean(4&e)}}setLogLevelMask(e){const t=(Number(e.error)&&1)|(Number(e.warning)&&2)|(Number(e.info)&&4);this._properties.childs().inputs.childs().__log_level.setValue(t)}performance(){return new b.WatchedValue(null)}profilingEnabled(){return!!this._properties.childs().inputs.childs().__profile?.value()}enableProfiling(e){this._properties.childs().inputs.childs().__profile?.setValue(e)}onAboutToBeDestroyed(){return this._aboutToBeDestroyed}priceScale(e){return e?this._model.mainSeries().priceScale():super.priceScale()}lastValueData(e,t,s){const i={noData:!0},r=this.metaInfo().isPlotForceOverlay(e),n=r?this._model.mainSeries().priceScale():this.priceScale();if(this._model.timeScale().isEmpty()||null===n||n.isEmpty()||this.data().isEmpty())return i;const o=this._model.timeScale().visibleBarsStrictRange(),a=this.firstValue(!0,r);if(null===o||null===a)return i;if(!this._properties.childs().visible.value())return i;const l=this._properties.childs().styles,h=this._properties.childs().ohlcPlots;let c,u;if(l&&l.childs()[e]&&(c=l.childs()[e]),h&&h.childs()[e]&&(c=h.childs()[e]),!c||0===c.childs().display.value())return i;const d=this.metaInfo().plots;for(u=0;ue.id()));if(a.length&&(r.parentSources=a),e){let e=this.data();const t=this._model.timeScale(),s=this._seriesDataRangeToSave(e);null!==s&&(e=e.range(s.firstBar(),s.lastBar())),r.data=e.state(),r.data.symbols=this._resolvedSymbols,r.data.graphics=(0,R.saveStudyGraphics)(this.graphics(),t.visibleBarsStrictRange()),r.data.plotOffsets=this._serverPlotOffsets.value()}this.ownerSource()&&(r.ownerSource=this.ownerSource()?.id());for(let e=0;e=0?e:0}}if(r.state?.inputs){const e=r.metaInfo.inputs.find((e=>"ILScript"===e.name));e&&delete r.state.inputs[e.id],delete r.state.inputs.__log_level,delete r.state.inputs.__profile}const l=this.stateCustomFields();return l&&(r.customFields=l),r}stateCustomFields(){const e=this._compileErrorStatus.value();if(e)return{compileErrorDescription:e.errorDescription}}restoreStateCustomFields(e){const t=e.compileErrorDescription;t&&this.setErrorCompilation([(0,p.ensureDefined)(t.editorError)])}restoreData(e){this._invalidateLastNonEmptyPlotRowCache(),this.data().restoreState(e),this._resolvedSymbols=e.symbols??{},this._graphics=e.graphics?(0,R.loadStudyGraphics)(e.graphics):(0,R.emptyStudyGraphics)(),this._postProcessGraphics(),this._serverPlotOffsets.setValue(e.plotOffsets??{}),this._setStatus({type:xt.StudyStatusType.Completed},!0)}hasStateForAlert(){return!1}stateForAlert(){throw new Error("Not implemented")}async stateForAlertAsync(){throw new Error("Not implemented")}idForAlert(){return super.idForAlert()}hasBarColorer(){return this._metaInfo.value().plots.some(L.isBarColorerPlot)}barColorer(){const e=this._metaInfo.value().plots;let t=null;for(let s=e.length-1;s>=0;s--)if((0,L.isBarColorerPlot)(e[s])){const e=new Bt(this,s);null===t?t=e:t.pushBackBarColorer(e)}return t}isSavedInStudyTemplates(){return this._metaInfo.value().inputs.every((e=>"bar_time"!==e.type))}restart(e){this._restarting=!0,this.clearData(),(e||ee.enabled("stop_study_on_restart"))&&this.stop(),setTimeout(this.start.bind(this),0)}stop(e,t){if(!0===e&&this._children)for(const e of this._children)e.stop(!0);this._stopStudyOnServer(),this.clearData(),this._unsubscribeToSessionId(),this.recalculate()}disconnect(){this._isStarted=!1,this._model.isSnapshot()||(this._resolvedSymbols={},this._resolvedSymbolsByInput={})}sourceId(){return this._id.value()}parentSources(){return this._sources.value()} parentSourcesVW(){return this._sources}symbolSource(){return this._symbolSource.value()}symbolSourceWV(){return this._symbolSource.readonly()}valueAt(e,t){return this.symbolSource().valueAt(e,t)}barsProvider(){return this._firstSourceOrSeries().barsProvider()}ownerSource(){return this.isChildStudy()?this._sources.value()[0]:super.ownerSource()}isChildStudy(){return this._sources.value().length>0}hasChildren(){return this._children.length>0}isStarted(){return this._isStarted}isRestarting(){return this._restarting}isActualInterval(){return this._isActualInterval}onIsActualIntervalChange(){return this._onIsActualIntervalChange}isVisible(){const e=this._properties.childs();if(this._model.collapsed().value()||!e.visible.value()||!this.isActualInterval())return!1;const t=this.metaInfo();if(t.plots.length>0)for(let s=0;se.isHibernated())).map((e=>e.start())));const r=!(this.isHibernationAllowed()&&!this.isVisible())||!0===t;if(this._chartApi&&this._chartApi.isConnected().value()&&r)try{await this._allSymbolsAreResolved(),await this._startAfterSymbolsResolved(e,t)}catch(e){const t=`ERROR: ${this._debugId()} start failed, ${e}`;Gt.logError(t),this._restarting=!1,"TooManyStudies"===e?.cause&&(0,S.showTooManyStudiesNotice)(this._chartApi.getStudyCounter())}r||void 0!==this._inputs||(this._inputs=this._apiInputs())}replaceData(e,t,s){this._invalidateLastNonEmptyPlotRowCache(),this.data().remove(e+1),this.data().addTail(s,t)}inputs(e){const t=(0,n.default)((0,_.clone)(Jt),e||{});t.skipOptionalEmptySymbolInputs&&(t.keepOptionalSymbolsEmpty=!0);return this._buildInputs(t)}data(){return this._data}moveData(e){this._ongoingDataUpdate=this._ongoingDataUpdate.then((()=>{this._invalidateLastNonEmptyPlotRowCache(),this._moveData(e),this.data().isEmpty()||this._onIndexDiffsApplied(e)}))}plots(){return this.data()}metaInfo(){return this._metaInfo.value()}status(){return this._compileActiveStatus.value()??this._compileErrorStatus.value()??this._status.value()}name(e){return e?this.metaInfo().shortDescription||"Study":this.metaInfo().description||"Study"}title(e,t,s,i,r,n){i=void 0===i?!this._showStudyArgumentsProperty.value():i;const o=JSON.stringify([e,t,s,i,r,n]);if(this._titleStrCache[o])return this._titleStrCache[o];if(this._titleInPartsCache[o])return this._joinTitlesParts(this._titleInPartsCache[o]);const a=this._title(e,t,s,i,r,n) ;return this._titleStrCache[o]=a,a}titleInParts(e,t,s,i,r){i=void 0===i?!this._showStudyArgumentsProperty.value():i;const n=JSON.stringify([e,t,s,i,r]);if(this._titleInPartsCache[n])return this._titleInPartsCache[n];const o=this._titleInParts(e,t,s,i,r);return this._titleInPartsCache[n]=o,o}inputsInParts(e,t=!0,s,i,r){const n=!this._showStudyArgumentsProperty.value(),o=ee.enabled("always_show_study_symbol_input_values_in_legend"),a=n&&o;if(n&&!o&&e===Y.TitleDisplayTarget.StatusLine)return null;const l=JSON.stringify([e,t,s,i,r]);if(this._inputsInPartsCache[l])return this._inputsInPartsCache[l];const h=[],c=this.metaInfo(),u=this._titleInputs((0,zt.toInputDisplayFlags)(e),i,!0),d=c.inputs.filter((e=>u.hasOwnProperty(e.id)&&(!a||"symbol"===e.type||e?.isAlwaysShownInLegend))).map((e=>{let t=u[e.id];if("symbol"===e.type){const s=this._properties.childs().inputs.child(e.id)?.value();if(s){const e=this._resolvedSymbolsByInput[s];e&&(t=this._model.symbolAliasService()?.getAliasByProName(e.pro_name)?.aliasName??t)}}return{meta:e,value:t}})),f={};if(d.length>0){if(this.isChildStudy())for(let s=0;s=0){const s=this.parentSourceForInput(a);if(s instanceof us){const n=s.metaInfo(),o=s.title(e,t,{},!0,i,r);if(1===n.plots.length)f[a]=o;else{const e=a.split("$")[1],t=n.plots[parseInt(e)]?.id,s=n.styles&&n.styles[t],i=s&&s.title||t;f[a]=o+": "+i}}}}d.forEach((({meta:e,value:t})=>{let i;i="time"===e.type?new Date(t).toISOString():(0,_.isNumber)(t)?(0,Lt.getNumericFormatter)().format(t):f&&f[t.toString()]||t.toString(),s&&s[i.toString()]&&(i=s[i.toString()]),h.push({title:(0,Ut.getTranslatedInputTitle)(e.name),value:i})}))}return this._inputsInPartsCache[l]=h,h}invalidateTitleCache(e){if(this._titleStrCache={},this._titleInPartsCache={},this._inputsInPartsCache={},!0===e&&this._children)for(let t=0;tt.update(e))),this._labelPaneViews.forEach((t=>t.update(e))), this._dataWindowView?.update(e),this._legendView?.update(e),this._statusView?.update(e),this._floatingTooltipView?.update(e),this._priceAxisViews.forEach((t=>t.update(e))),this._priceLinesAxisViews.forEach((t=>t.update(e))),this._inputsLinesPaneView?.update(e),this._inputsAnchorsPaneView?.update(e),this._inputsTimeAxisPaneViews.forEach((t=>t.update(e))),this._inputsPriceAxisPaneViews.forEach((t=>t.update(e)))),i||(this._forceOverlaysPaneViews.forEach((t=>t.update(e))),this._forceOverlayLabelPaneViews.forEach((t=>t.update(e))),this._forceOverlayPriceAxisViews.forEach((t=>t.update(e)))),"data-source-change"===e.type&&e.sourceId===this.id()&&e.clearData&&this._children.forEach((e=>e.updateAllViews({type:"data-source-change",sourceId:e.id(),clearData:!0})))}removeByRemoveAllStudies(){return!0}studyName(){return this._studyName}nearestIndex(e,t,s){return this.data().search(e,t,s)?.index}getMinFirstBarIndexForPlot(e){const t=this._properties.childs(),s=this._metaInfo,i=t.styles.childs()[e]?.child("showLast")?.value()??t.filledAreasStyle.childs()[e]?.child("showLast")?.value()??s.value().styles?.[e]?.showLast??t.ohlcPlots.childs()[e]?.child("showLast")?.value()??s.value().ohlcPlots?.[e]?.showLast??null;if(null===i)return-1/0;const r=this.data().lastIndex();return null===r?-1/0:r-i+1}guiPlotName(e,t){const s=this._metaInfo.value(),i=s.plots.find((e=>e.id===t));if(void 0!==i){return((0,L.isOhlcPlot)(i)?s.ohlcPlots?.[i.target]?.title:s.styles?.[t]?.title)??this.title(e)}return this.title(e)}childStudyByRebind(){return this._childStudyByRebind}isPine(){return void 0!==this._metaInfo.value().pine}isStandardPine(){return this.isPine()&&A.StudyMetaInfo.isStandardPine(this._metaInfo.value().id)}isLinkedToSeries(){return!0===this._metaInfo.value().linkedToSeries}preferredZOrder(){return!1===this._metaInfo.value().behind_chart?0:null}defaultPlotIdForAlert(){return this._metaInfo.value().plots?.[0]?.id??null}resolvedSymbolInfoBySymbol(e){return this._resolvedSymbols&&e&&this._resolvedSymbols[this._getSymbolForResolve(e)]||null}hasPendingUnresolvedSymbols(){return this._pendingResolveSymbols.size>0}hasSymbolInputs(){return this._metaInfo.value().inputs.some((e=>"symbol"===e.type))}currency(){if(null!==this._currencySourceSymbolInfo)return(0,Tt.symbolCurrency)(this._currencySourceSymbolInfo);const e=this.metaInfo();return Boolean(e)&&e.is_price_study?this._firstSourceOrSeries().currency():null}currencySourceSymbolInfo(){return this._currencySourceSymbolInfo??this.symbolSource()?.symbolInfo()??null}unit(){const e=this.metaInfo();return Boolean(e)&&e.is_price_study?this._firstSourceOrSeries().unit():null}canOverrideMinTick(){return!1}dataWindowView(){return this._dataWindowView}statusView(){return this._statusView}legendView(){return this._legendView}chartFloatingTooltipView(){return this._floatingTooltipView}pineSourceCodeModel(){return Promise.resolve(null)}alertSourceModel(){return this._alertSourceModel}inputsForAlertState(){return this.inputs()}sessionId(){return this._firstSourceOrSeries().sessionId()}sessionIdChanged(){ return this._firstSourceOrSeries().sessionIdChanged()}getSymbolString(e){return""===e?"":(0,U.encodeExtendedSymbolOrGetSimpleSymbolString)(this._getSymbolObject(e))}onStatusChanged(){return this._statusChanged}onDataUpdated(){return this._dataUpdated}symbolsResolved(){return this._symbolsResolved}onHibernationStateChange(){return this._onHibernationStateChange}valuesProvider(){return this._valuesProvider}legendValuesProvider(){return new E(this,this.model())}tableViewValuesProvider(){return this._tableViewValuesProvider}statusProvider(e){return new $.StudyStatusProvider(this)}chartFloatingTooltipValuesProvider(){return new K(this,this.model())}correctScaleMargins(e){if("Volume"===this.metaInfo().shortId){const t=this.model().paneForSource(this);return null!==t&&t.isOverlay(this)&&t.containsMainSeries()?{top:.75,bottom:0}:{top:e.top,bottom:0}}return e}canBeHiddenByGlobalFlag(){return!0}isSourceHidden(){return!this.isVisible()||this.canBeHiddenByGlobalFlag()&&W.hideAllIndicators().value()}wasCompletedBefore(){return this._wasCompletedBefore}paneViews(e){const t=this._model.mainPane();if(this.isSourceHidden())return null;if(!e.hasPriceDataSource(this))return e!==t?null:this._forceOverlaysPaneViews;const s=[];return!this._startMovingPoint&&this._wasCompletedBefore&&s.push(...this._paneViews.filter((e=>!e.isForceOverlay?.()))),this._inputsLinesPaneView&&(this._startMovingPoint||this._model.selection().isSelected(this))&&s.push(this._inputsLinesPaneView),this._inputsAnchorsPaneView&&s.push(this._inputsAnchorsPaneView),e===t&&s.push(...this._forceOverlaysPaneViews),s}labelPaneViews(e){const t=this._model.mainPane();if(this.isSourceHidden()||!e.hasPriceDataSource(this))return this._metaInfo.value().hasForceOverlayPlots()?e!==t?null:this._forceOverlayLabelPaneViews:null;const s=[...this._labelPaneViews];return e===t&&s.push(...this._forceOverlayLabelPaneViews),s}timeAxisViews(){return this._model.selection().isSelected(this)?this._inputsTimeAxisPaneViews:null}priceAxisViews(e,t){if(t!==this.priceScale()&&t===this._model.mainSeries().priceScale()&&!e.hasDataSource(this))return this._forceOverlayPriceAxisViews;const s=this._properties.childs().oldShowLastValue;if(s&&!s.value())return null;let i=this._priceAxisViews.slice();return this._model.selection().isSelected(this)&&(i=i.concat(this._inputsPriceAxisPaneViews)),t===this._model.mainSeries().priceScale()&&(i=i.concat(this._forceOverlayPriceAxisViews)),e.findTargetPriceAxisViews(this,t,i,this._priceLinesAxisViews)}movable(){return null!==this._inputsAnchorsPaneView}startMoving(e,t,s,i){this._startMovingPoint=e}move(e,t,s,i){if(void 0!==e.logical&&null!==this._startMovingPoint){if(Array.isArray(t)){const s=t;this._updateInputValue(e.logical,s[0]),this._updateInputValue(e.logical,s[1])}else this._updateInputValue(e.logical,t);this.updateAllViews((0,N.sourceChangeEvent)(this.id()))}}endMoving(e,t){return this._startMovingPoint=null,{indexesChanged:!1,pricesChanged:!1}}clearData(){this._invalidateLastNonEmptyPlotRowCache(), this._ongoingDataUpdate=this._ongoingDataUpdate.then((()=>{this._clearData(),this._graphics instanceof R.LiveStudyGraphics&&this._graphics?.clear(),this._serverPlotOffsets.setValue({})})),this.hasBarColorer()&&this._model.mainSeries().invalidateBarStylesCache(),this.updateAllViews((0,N.sourceChangeEvent)({sourceId:this.id(),clearData:!0}))}convertYCoordinateToPriceForMoving(e,t){const s=this.priceScale();if(!t||!s||s.isEmpty())return null;const i=t.firstValue();return null===i?null:s.coordinateToPrice(e,i)}processHibernate(e){const t=this.isVisible();if(!this.isStarted()&&t&&(this._sources.value().forEach((e=>{e.processHibernate()})),this.start(void 0,void 0,e),this._onHibernationStateChange.fire(!1)),this.isHibernationAllowed()&&this.isStarted()&&!t){for(const e of this._children)e.processHibernate();this.stop(void 0,e),this._onHibernationStateChange.fire(!0)}}isHibernationAllowed(){return!this.metaInfo().historyCalculationMayChange&&(!this.hasChildren()||!!this._model.collapsed().value()&&this._children.every((e=>e.isHibernationAllowed())))}isPlotVisibleAt(e,t){let s;const i=this.metaInfo().plots.find((t=>t.id===e));if(s=void 0!==i?(0,L.isOhlcPlot)(i)?this._properties.childs().ohlcPlots.childs()[i.target]:this._properties.childs().styles.childs()[e]:this._properties.childs().ohlcPlots.childs()[e],void 0===s)throw new Error(`Study does not contain ${e} plot`);const r=s.childs().display.value();return null!==r&&(r&t)===t}recalculate(){const e=this._model.paneForSource(this);this._model.recalculatePane(e,(0,N.sourceChangeEvent)(this.id())),this._model.updateSource(this)}maxOffset(){return this._maxOffset}onStart(){return this._onStart}onParentSourcesChanges(){return this._onParentSourcesChanges}isHibernated(){return!this.isVisible()&&!this.isStarted()}graphicsViewsReady(){return this._graphicsViewsReady}setLoadingCompilationActive(e){0}setErrorCompilation(e){0}hasCompileError(){return null!==this._compileErrorStatus.value()}turnaround(e){if(!e)return this._turnaround;return function(e,t){let s=t.turnaround,i=[t];for(;i.length>0;){let e=[];const t=[];i.forEach((s=>{const i=J(s.sourceStudies).sort(q);if(i.length>0){e=e.concat(i);const s=i.map((e=>e.turnaround)).join("_");t.push(s)}})),t.length&&(s=t.join("_")+"_"+s),i=e}return e+"_"+s}(this._series.seriesSource().turnaround(),Z(this))}canHaveChildren(){return this._canHaveChildren=this._canHaveChildren??A.StudyMetaInfo.canHaveChildren(this._metaInfo.value()),this._canHaveChildren}setChild(e){-1===this._children.indexOf(e)&&this._children.push(e)}unsetChild(e){const t=this._children.indexOf(e);~t&&this._children.splice(t,1)}getAllChildren(){const e=this._children.slice();for(let t=0;te.id()===t))??null}return this._series}priceStep(){return this._priceStep||this._firstSourceOrSeries().priceStep(!1)}recreatePriceFormatter(){ this._recreatePriceFormattingDependencies()}setOwnerSource(e){super.setOwnerSource(e),this._recreatePriceFormattingDependencies()}onTagsChanged(){return this._tagsChanged}getPropertyDefinitionsViewModel(){return null===this._definitionsViewModel?this._getPropertyDefinitionsViewModelClass().then((e=>null===e||this._isDestroyed?null:(null===this._definitionsViewModel&&(this._definitionsViewModel=new e(this._model.undoModel(),this)),this._definitionsViewModel))):Promise.resolve(this._definitionsViewModel)}calculationTime(){return this._calculationTime.readonly()}contextMenuStatName(){return"IndicatorContextMenu"}metaInfoWV(){return this._metaInfo.readonly()}async patchPropertiesAfterResetDefaults(){throw new Error("Not implemented")}_getPropertyDefinitionsViewModelClass(){return Promise.resolve(null)}_alertMetaInfo(){return this.metaInfo()}_createStudyOnServer(){if(this._isDestroyed)return!1;this._isStarted=!0,this._incrementTurnaround();const e=(0,p.ensureDefined)(this._inputs);let t;return t=this._chartApi.createStudy(this.sourceId(),this._turnaround,this.isChildStudy()?(0,p.ensureNotNull)(this._sources.value()[0].sourceId()):(0,p.ensureNotNull)(this._series.seriesSource().instanceId()),this._studyName.value(),e,this._handler,this._studySpec()),t?(performance.mark(`calculate_study_${this._id.value()}`),!0):(this._isStarted=!1,t)}_stopStudyOnServer(){this._chartApi&&this._chartApi.isConnected().value()&&this.isStarted()&&(this._chartApi.removeStudy(this.sourceId()),this._setStatus({type:xt.StudyStatusType.Undefined})),performance.clearMarks(`calculate_study_${this.sourceId()}`),this._isStarted=!1}_modifyStudyOnServer(e,t){this._chartApi.modifyStudy(this.sourceId(),this._turnaround,e,this._handler,t),performance.mark(`calculate_study_${this.sourceId()}`)}_sendNotifyCommand(e,t){this._chartApi.notifyStudy(this.sourceId(),e,t)}_transformData(e){}_plotsDataRange(){const e=this.plots().firstIndex(),t=this.plots().lastIndex();return null!==e&&null!==t?[e,t]:null}_invalidateLastNonEmptyPlotRowCache(){this._lastNonEmptyPlotRowCache={}}_collectDepsForAlert(){throw new Error("Not implemented")}_allInputsAreValid(){if(null===this._visibleTimeRangeInputs?.value())return!1;for(const e of this._metaInfo.value().inputs)if("bar_time"===e.type){const t=e.id;if(null==this._properties.childs().inputs.childs()[t].value())return!1}return!0}async _startAfterSymbolsResolved(e,t){await Promise.all(this._sources.value().map((e=>!e.isStarted()||e.isRestarting()?new Promise((t=>{e.onStart().subscribe(this,t,!0)})):Promise.resolve()))),this.isStarted()&&!this._restarting||(this._restarting=!1,this._allInputsAreValid()&&!this.metaInfo().isTVScriptStub&&(this._inputs=this._apiInputs(),this._createStudyOnServer()&&(this._subscribeToSessionId(),this._onStart.fire(),!0===e&&this._children&&await this._children.map((e=>e.start(!0,t))))))}async _changeInputsImpl(e,t){const i=this._calcSources(),r=this._metaInfo.value(),n=os(),o=()=>{for(const s of r.inputs){if("source"!==s.type)continue;const i=e[s.id].v,r=t[s.id].v;if(i!==r){(0, p.ensureDefined)(this._properties.childs().inputs.child(s.id)).setValue(r)}}};if(this.isStarted()&&this._chartApi.isConnected().value()&&n>0&&!this._chartApi.canCreateStudy(this._studySpec(!0),!0).success){const e=window.user.pro_plan,t="pro_premium_expert"===e||"pro_premium_expert_trial"===e;return createGoProDialog({feature:"studyOnStudy",hideLimitTable:t,actions:e&&t?[{text:m.t(null,void 0,s(15462)),action:PredefinedAction.Close}]:void 0}),void o()}this._inputs=e;let a=!1;const l=Object.values(Q.RangeDependentStudyInputNames);for(const s of Object.keys(e))if(JSON.stringify(e[s])!==JSON.stringify(t[s])&&!l.includes(s)){a=!0;break}this._incrementTurnaround(),a&&this.disablePriceRangeReady();try{await this._updateParentSources(i,n,!0),this._modifyStudyOnServer(e,n),this._studyModified=!0}catch(e){Gt.logError(`Error applying parent sources: ${e}`),o()}this.invalidateTitleCache()}_createPriceAxisView(e){return new Rt.StudyPriceAxisView(this,{plotIndex:e})}_createPriceLineAxisView(e){return new Ot.StudyPriceLineAxisView(this,e)}_createStudyPlotPaneView(e){return new lt.StudyPlotPaneView(this,this._series,this._model,e)}_createViews(){this._priceAxisViewsBase=[],this._forceOverlayPriceAxisViews=[],this._priceLinesAxisViews=[],this._paneViews=[],this._forceOverlaysPaneViews=[],this._labelPaneViews=[],this._forceOverlayLabelPaneViews=[];const e=new Set,t=this.metaInfo(),s=Boolean(t.usePlotsZOrder),i=new Map,r=this._properties.childs();if(r.filledAreasStyle&&t.filledAreas)for(let e=0;e{const n=r.bands.childs()[t];if(n&&n.childs().visible.value()){const t=new St(n,this),r=s?(0,p.ensureDefined)(e.zorder):i.size;rs(r,i),i.set(r,{paneViews:[t]})}})),r.bandsBackground&&((0,p.assert)(!s,"'usePlotsZOrder' flag does not supported"),i.set(i.size,{paneViews:[new wt(this)]}));const n=this._paneViews,o=this._forceOverlaysPaneViews;this._createGraphicsPaneViews().then((e=>{for(let t=0;te-t));for(let e=0;e0){const t=(0,p.ensureNotNull)(this.barColorer()).firstColoredBar(e[0].index);null!==t&&this._model.mainSeries().invalidateBarStylesCache(t)}null!==t&&this._postProcessGraphics();const r=this._model.paneForSource(this);if(this._model.recalculatePane(r,(0,N.sourceChangeEvent)({sourceId:this.id(),firstUpdatedTimePointIndex:i??void 0,nonSeriesOnly:0===e.length})),this._updateSources(),e.length){const t=e[e.length-1].index,s=e[0].index;this._dataRangeUpdated.fire({type:"partial",startIndex:s, endIndex:t})}else this.data().isEmpty()&&this._dataRangeUpdated.fire({type:"full"})}_titleInputs(e,t,s){return this.inputs(this._titleInputsOptions(e,t,s))}_titleInputsOptions(e,t,s){return{symbolsForDisplay:!0,skipHiddenInputs:!0,skipFakeInputs:!1,fakeInputsForDisplay:!0,asObject:!0,skippedGroups:[],skippedInputs:this._skippedTitleInputs(),noExchanges:t,noResolution:s,priceInputsForDisplay:!0,skipOptionalEmptySymbolInputs:Qt,displayMask:e}}_postProcessGraphics(){this._graphicsPriceAxisViews=this._createGraphicsPriceAxisViews(),this._concatPriceAxisViews()}async _createGraphicsPaneViews(){return(0,R.createGraphicsPaneViews)(this,this.model())}_createGraphicsPriceAxisViews(){return(0,R.createGraphicsPriceAxisViews)(this)}_subscribeToSessionId(){!this._isSubscribedToSessionId&&this.hasSymbolInputs()&&(this.sessionIdChanged().subscribe(this,this._onSessionIdChanged),this._isSubscribedToSessionId=!0)}_recreateFormatter(e){let t=e;if(t){const e=this._model.symbolAliasService()?.getAliasByProName(t.pro_name);e&&(t=(0,r.default)(t),(0,n.default)(t,e.formattingOptions??{}))}this._recreatePlotsFormatters(t),this._formatter=this._tryCreateFormatter(t),this._defaultFormatter=this._tryCreateDefaultFormatter(t),this._formatterChanged.fire();const s=this.priceScale();null!==s&&s.updateFormatter(),this.getAllChildren().forEach((e=>{e.recreatePriceFormatter()})),this._model.fullUpdate()}_recreatePriceFormattingDependencies(e){this._recreateFormatter(e),this._recreatePriceStep()}_title(e,t,s,i,r,n){const o=this._titleInParts(e,t,s,i,r,n);return this._joinTitlesParts(o)}_postProcessPriceRange(e,t){if(e&&e.minValue()===e.maxValue()&&!this.metaInfo().is_price_study){const t=.005*e.minValue();e=new M.PriceRange(e.minValue()-t,e.maxValue()+t)}const s=t.targetPriceScale;return s&&s.isLog()&&e?new M.PriceRange(s.priceToLogical(e.minValue()),s.priceToLogical(e.maxValue())):e}_titleInParts(e,t=!0,i,r,n,o){const a=[m.t(this.name(t),{context:"study"},s(83477))];let l=[];if(!r||ee.enabled("always_show_study_symbol_input_values_in_legend")){const s=this._getMTFResolutionInputTitle();null!==s&&s.length>0&&a.push(s);l=(this.inputsInParts(e,t,i,n,o)??[]).map((e=>e.value))}return[a.join(" · "),l]}_seriesDataRangeToSave(e){return this._model.timeScale().visibleExtendedDataRange(e,0)}_getSymbolForResolve(e){return this.getSymbolString(this._getSymbolForApi(e))}_getSymbolForApi(e){return e}_getSymbolObject(e){const t={symbol:e},s=this.currency();return null!==this._currencySourceSymbolInputProperty&&null!==this._currencySourceSymbolInfo&&this._getSymbolForApi(this._currencySourceSymbolInputProperty.value())===e&&(t["currency-id"]=s),t.session=this.sessionId(),t}_onSymbolResolved(e,t,s){this._onCurrencyMayChange()}_onSymbolResolvingStart(e,t){}_onSymbolError(){}_setStatus(e,t){const s=this.isFailed();this._status.setValue(e),e.type===xt.StudyStatusType.Completed?this._wasCompletedBefore=!0:e.type!==xt.StudyStatusType.Error&&e.type!==xt.StudyStatusType.Undefined||(this._wasCompletedBefore=!1),t||(this._statusView?.update((0, N.sourceChangeEvent)(this.id())),this._model.updateSource(this),this._statusChanged.fire(this.status())),s!==this.isFailed()&&this._updateAlertCreationAvailable()}_onPropertiesChanged(){this._restarting||(this._inputs?this._tryChangeInputs():this._chartApi&&this._chartApi.isConnected().value()&&this.restart());this._metaInfo.value();this._recreatePaneViews(),(0,Nt.emit)("study_properties_changed",this._id.value())}_lastNonEmptyPlotRow(e){if(!(0,_.isInteger)(e))return Gt.logDebug("_lastNonEmptyPlotRow: incorrect plotIndex"),null;let t=this._lastNonEmptyPlotRowCache[e]??null;if(null!==t)return t;return t=this.data().findLast(((t,s)=>void 0!==s[e]),1e3),null===t?null:(this._lastNonEmptyPlotRowCache[e]=t,t)}_onCurrencyChanged(){"alwaysOff"!==(0,At.currencyUnitVisibilityProperty)().value()&&this._model.fullUpdate(),this.isStarted()&&this._tryChangeInputs(),this._currencyChanged.fire()}_apiInputs(){return this.inputs({keepOptionalSymbolsEmpty:!0})}async _tryChangeInputs(){const e=this.isStarted()&&this._chartApi.isConnected().value(),t=this._allInputsAreValid(),s=((0,p.ensureDefined)((0,_.clone)(this._inputs)),this._apiInputs()),i=JSON.stringify(s),r=i!==JSON.stringify(this._inputs);if(e&&t)try{if(await this._allSymbolsAreResolved(),i!==JSON.stringify(this._apiInputs()))return this._tryChangeInputs();if(this._isStopped())return void(r&&this.disablePriceRangeReady());r&&await this._changeInputsImpl(s,(0,p.ensureDefined)((0,_.clone)(this._inputs)))}catch(e){Gt.logError(`ERROR: ${this._debugId()} _tryChangeInputs: cannot modify study, ${e}`)}else if(e&&!t&&this.stop(!0),!e&&t&&this.start(!0),r){const e=this._calcSources(),t=os(this._metaInfo.value());this._updateParentSources(e,t,!0),this._inputs=s}this._tagsChanged.fire()}_onCurrencyMayChange(){if(null!==this._currencySourceSymbolInputProperty){const e=this.currency();this._updateCurrencySourceSymbolInfo(),e!==this.currency()&&this._onCurrencyChanged()}}_fillPrecalculatedAutoscaleInfo(e,t,s){const i=this._metaInfo.value(),r=this.properties().childs(),n=new Set,o=i.filledAreas||[];for(let e=0;e!(0,L.isPlotWithTechnicalValues)(e))).filter((e=>i.isPlotForceOverlay(e.id)?s.targetPriceScale===this._model.mainSeries().priceScale():s.targetPriceScale===this.priceScale()&&!s.forceOverlayOnly)).filter((e=>n.has(e.id)||this.isPlotVisibleAt(e.id,1))).reduce(((s,i)=>this._applyPlotToPrecalculatedAutoscaleInfo(e,t,s,i)),{fields:[],useMainSeriesRange:!1,baseValueMinMax:null})}_firstSourceOrSeries(){return this._sources.value()[0]??this._series}_skipHistogramBaseOnAutoScale(){return!1}_tryCreateFormatter(e){const t=void 0===e?this.symbolSource().symbolInfo():e;return hs(this._metaInfo.value().format,this._priceScaleByProperties(),t,this.properties().childs().precision.value())}_tryCreateDefaultFormatter(e){return this._tryCreateFormatter(e)}_mergeData(e){return this._invalidateLastNonEmptyPlotRowCache(),this.data().merge(e)} _skippedTitleInputs(){return this._hideMatches.filter((e=>e.plotIds.every((e=>0===this._getPlotDisplayValue(e))))).map((e=>e.id))}_getPlotDisplayValue(e){return this.properties()?.childs()?.styles?.childs()?.[e]?.childs()?.display?.value()}_onStudyError(e){performance.clearMarks(`calculate_study_${this.sourceId()}`),this._handleStudyError(this._createStudyError(e)),this._enablePriceRangeReady()}_onStudyCompleted(e){if(performance.getEntriesByName(`calculate_study_${this.sourceId()}`).length){try{const e=performance.measure(`measure_study_${this.sourceId()}`,`calculate_study_${this.sourceId()}`);this._calculationTime.setValue(e.duration)}catch(e){Gt.logError("Error during measuring study calculation time")}performance.clearMarks(`calculate_study_${this.sourceId()}`),performance.clearMeasures(`measure_study_${this.sourceId()}`)}this._studyModified&&(this.clearData(),this._studyModified=!1),this._setStatus({type:xt.StudyStatusType.Completed}),this._statusView?.update((0,N.sourceChangeEvent)(this.id()));const t=this._model.paneForSource(this);this._model.recalculatePane(t,(0,N.sourceChangeEvent)(this.id())),this._updateSources();const s=Vt.InvalidationMask.full();null!==this._model.appliedTimeFrame().value()&&s.lockVisibleTimeRangeOnResize(),this._model.invalidate(s)}_clearData(){this._data.clear(),this._dataRangeUpdated.fire({type:"full"})}_moveData(e){this.data().move(e)}_defaultErrorTitle(){return"Runtime error"}_incrementTurnaround(){this._turnaround="st"+ ++this._turnaroundCounter}_checkTurnaround(e){return e===this._turnaround||e===this._model.mainSeries().seriesSource().turnaround()||e===this.turnaround(!0)}_updateMaxOffsetValue(){let e=-1/0;for(const t of this._metaInfo.value().plots)e=Math.max(this.offset(t.id),e);this._maxOffset.setValue(e)}_rightOffsetToUnixTime(e){if(this._series.bars().size()>=e){const t=(0,p.ensureNotNull)(this._series.bars().lastIndex())-e;return(0,p.ensureNotNull)(this._series.bars().valueAt(t))[0]}return null}_concatPriceAxisViews(){this._priceAxisViews=[...this._priceAxisViewsBase,...this._graphicsPriceAxisViews]}_onStudyLoading(e){this._setStatus({type:xt.StudyStatusType.Loading,startTime:Date.now()}),this._statusView?.update((0,N.sourceChangeEvent)(this.id())),this._model.updateSource(this)}_handleStudyError(e){this.clearData(),this._setStatus(e),this._statusView?.update((0,N.sourceChangeEvent)(this.id())),this._model.updateSource(this)}_createStudyError(e){let t;return t=(0,_.isString)(e)?{error:this._getStudyErrorText(e),title:e.includes("study_not_auth")?"Access error":this._defaultErrorTitle()}:{...e,title:e.title??this._defaultErrorTitle()},(0,xt.createStudyError)(t,this.symbolSource().symbolInfo()?.exchange)}_updateSources(){this._model.updateSource(this),this.hasBarColorer()&&this._model.updateSource(this._model.mainSeries())}_unsubscribeToSessionId(){this._isSubscribedToSessionId&&(this.sessionIdChanged().unsubscribe(this,this._onSessionIdChanged),this._isSubscribedToSessionId=!1)}_onSessionIdChanged(){this.restart(!0)}_recreatePriceStep(){let e=null ;const t=this._priceScaleByProperties()??this._priceScaleByMetaInfo();null!==t&&(e=1/t),this._priceStep!==e&&(this._priceStep=e,this._priceStepChanged.fire())}_recreatePlotsFormatters(e){this._plotFormatters.clear();const t=this._metaInfo.value(),s=t.format,i=this._priceScaleByProperties(),r=void 0===e?this.symbolSource().symbolInfo():e;for(const[e,n]of Object.entries(t.ohlcPlots??{}))if(n?.format){const t=hs(ls({...s,...n?.format}),i,r,this.properties().childs().precision.value());t&&this._plotFormatters.set(e,t)}for(const[e,n]of Object.entries(t.styles??{}))if(n?.format){const t=hs(ls({...s,...n?.format}),i,r,this.properties().childs().precision.value());t&&this._plotFormatters.set(e,t)}for(const e of t.plots)if((0,L.isOhlcPlot)(e)){const t=this._plotFormatters.get(e.target);t&&this._plotFormatters.set(e.id,t)}}_joinTitlesParts(e){const t=e[1]?e[1].join(", "):"";return e[0]+(t.length>0?" ("+t+")":"")}_getMTFResolutionInputTitle(){const e=this.metaInfo();for(let t=0;ti),(()=>i)).then(this._onDataUnpacked.bind(this,e,t.indexes,s)),this._ongoingDataUpdate}_allSymbolsAreResolved(){const e=this._inputSymbols(),t=[];let s=!1;for(const i of e){const e=this._getSymbolForResolve(i);if(""!==e)if(this._resolvedSymbols[e])s=!0;else{const s=this._resolveSymbol(e,i);t.push(s)}}if(0===t.length){const e=Promise.resolve();return s?e.then((()=>this._symbolsResolved.fire())):e}return Promise.all(t).catch((e=>(this._inputSymbols().includes(e)&&this.stop(!0),this._setStatus({type:xt.StudyStatusType.Error,errorDescription:{error:$t}}),this._model.updateSource(this),Promise.reject("Invalid symbol, "+e)))).then((()=>{this._symbolsResolved.fire(),this._recheckLineToolsActuality()}))}_resolveSymbol(e,t){if(""===e)return Promise.resolve();let s=this._pendingResolveSymbols.get(e);return void 0!==s||(s=new Promise(((s,i)=>{this._onSymbolResolvingStart(e,t),this._chartApi.resolveSymbol((0,j.makeNextSymbolId)(),e,(r=>{switch(this._pendingResolveSymbols.delete(e),r.method){case"symbol_resolved":{this._setStatus({type:xt.StudyStatusType.Undefined});const i=r.params[1];this._resolvedSymbols[e]=i,this._resolvedSymbolsByInput[t]=i,this.invalidateTitleCache(!0),this._onSymbolResolved(e,t,i),s();break}case"symbol_error":if(this._setStatus({type:xt.StudyStatusType.Error,errorDescription:{error:r.params[1]}}),this._onSymbolError(),r.params[1]===G.permissionDenied&&r.params[2]){if(r.params[2]!==G.SymbolErrorPermissionDeniedReason.Symbol)return void this._resolveSymbol(r.params[2],t).then(s);if(r.params[3])return void this._resolveSymbol(r.params[3],t).then(s)}0,i(t)}}))})),this._pendingResolveSymbols.set(e,s)),s}_recheckLineToolsActuality(){const e=this._model.paneForSource(this) ;null!==e&&e.sourcesByGroup().lineSourcesForAllSymbols().forEach((e=>{e.ownerSource()===this&&e.calcIsActualSymbol()}))}_sendTelemetryCounter(e,t){void 0===t&&(t=this._getTelemetryAdditionalData());const s={count:1,additional:t};telemetry.sendChartReport(e,s)}_getTelemetryAdditionalData(){let e="";const t=this._metaInfo.value();return t.pine&&t.pine.version&&t.shortId.indexOf("USER")>=0&&(e="_v"+t.pine.version),{symbol:this.series().actualSymbol(),resolution:this.series().interval(),study:t.shortId+e}}_onSourceFormatterChanged(){null===this._formatter&&(null!==this._priceScale&&this._priceScale.updateFormatter(),this._formatterChanged.fire())}_onSourcePriceStepChanged(){null===this._priceStep&&this._priceStepChanged.fire()}_bandsFirstValue(e){const t=this._metaInfo.value();if(!t.bands)return null;for(let s=0;s=0?t:e} return e}if(r.isTVScript||r.pine){if("text"===s)return r.defaults.inputs?.text??"";if("pineId"===s)return r.scriptIdPart;if("pineVersion"===s)return r.pine?r.pine.version:"-1";if("color"===e.type&&r.isRGB){const e=i.inputs.childs()[s].value();return(0,I.colorToInteger)(e)}if("price"===e.type){const e=i.inputs.childs()[s].value();return t.priceInputsForDisplay?this.formatter().format(e):e}}return i.inputs.childs()[s].value()}_getStudyIdWithLatestVersion(){return A.StudyMetaInfo.getStudyIdWithLatestVersion(this.metaInfo())}_debugId(){const e=[];e.push(this._id.value());const t=this._metaInfo.value();return e.push(t.fullId),e.push(t.description),JSON.stringify({study:e})}_hasAvailableAlertPlots(){return!1}_hasAlertConditions(){return!1}_hasAlertFunction(){return!1}async _updateParentSources(e,t,s){if(this._sources.value().forEach((e=>e.unsetChild(this))),s&&await Promise.all(e.map((e=>e.isStarted()?Promise.resolve():e.start(!1,!0)))),e.forEach((e=>e.setChild(this))),this._setSources(e),this._recreatePriceFormattingDependencies(),0!==t&&this._sources.value().length<=1){const e=this._firstSourceOrSeries(),t=this._priceScale,s=(0,p.ensureNotNull)(e.priceScale());if(t!==s){const t=this._model.paneForSource(this),i=(0,p.ensureNotNull)(this._model.paneForSource(e));t===i&&i.move(this,s,!0)}}}_calcSources(){const e=this._properties.childs().inputs.state();return A.StudyMetaInfo.getSourceIdsByInputs(this._metaInfo.value().inputs,e).map((e=>{if("high"===e||"open"===e||"low"===e||"close"===e||"hl2"===e||"ohl3"===e||"ohlc4"===e)return null;return this._model.allStudies().find((t=>t.canHaveChildren()&&t.id()===e))??null})).filter(_.notNull)}_isStopped(){return!this.isStarted()}_onDataUnpacked(e,t,s,i){if(this._isDestroyed)return;"nochange"!==t&&this._processPlotOffsets(i),this._transformData(e);const r=this._mergeData(e);null!==i&&(i.indexes_replace?((0,p.assert)("nochange"!==t),this._graphics.replaceIndexesTo(t)):("nochange"!==t&&this._graphics.replaceIndexesTo(t),void 0!==i.graphicsCmds&&this._graphics.processCommands(i.graphicsCmds))),this._onDataUpdated(e,i,t,r&&r.index),this.priceRangeReady()||this._enablePriceRangeReady()}_processPlotOffsets(e){if(e&&e.indexes_replace)return;const t=this._serverPlotOffsets.value();this._serverPlotOffsets.setValue(e&&e.offsets||{}),(0,i.default)(t,this._serverPlotOffsets.value())||this.updateAllViews((0,N.sourceChangeEvent)({sourceId:this.id(),clearData:!0})),this._updateMaxOffsetValue()}_applyPlotToPrecalculatedAutoscaleInfo(e,t,s,i){const r=i.id,n=this._properties.childs().styles.childs()[r],o=(0,L.isShapesPlot)(i)||(0,L.isCharsPlot)(i);s.useMainSeriesRange=s.useMainSeriesRange||(0,L.isArrowsPlot)(i);let a=(0,L.isLinePlot)(i)||(0,L.isOhlcPlot)(i);if(o){const e=(0,p.ensureDefined)(n).childs().location.value(),t=[D.MarkLocation.Absolute,D.MarkLocation.Top,D.MarkLocation.Bottom].indexOf(e)<0;s.useMainSeriesRange=s.useMainSeriesRange||o&&t,a=a||e===D.MarkLocation.Absolute}if(!a)return s;const l={name:r,offset:this.offset(r)},h=n.childs().plottype.value() ;if(!this._skipHistogramBaseOnAutoScale()&&[L.LineStudyPlotStyle.Histogram,L.LineStudyPlotStyle.Columns,L.LineStudyPlotStyle.Area].indexOf(h)>=0){const i=(this._metaInfo.value().styles??{})?.[r]?.histogramBase;if(void 0===i)return s;const n=this.data().minMaxOnRangeCached(e,t,[l]);return(0,_.isNumber)(i)&&null!==n&&(s.baseValueMinMax=(0,T.mergeMinMax)(s.baseValueMinMax,{min:i,max:i}),s.baseValueMinMax=(0,T.mergeMinMax)(s.baseValueMinMax,n)),s}return s.fields.push(l),s}async _onSourceInputChanged(){if(!this.isStarted()){this._calcSources();Kt}}_buildInputs(e){(0,p.assert)(!!e,"options not set");let t={};try{t=this._prepareInputs(e)}catch(e){Gt.logWarn("Failed to prepare study inputs: "+e)}if(e.asObject){const e={};return Object.keys(t).forEach((s=>{null!=t[s]&&(e[s]=t[s])})),e}{const e=[];return Object.keys(t).forEach((s=>{null!=t[s]&&e.push(t[s])})),e}}_prepareInput(e,t){const s=this._prepareInputValue(e,t);return!e.isFake||t.fakeInputsForDisplay||t.onlyAtomValues?s:{v:s,f:!0,t:e.type}}_plotsForAlert(){return[]}_formatterStateForAlert(){try{const e=this.formatter();return FormattersSerializer.isSerializable(e)?FormattersSerializer.serialize(e):null}catch{return null}}_calcIsActualInterval(){const e=this._isActualInterval;this._isActualInterval=(0,Ct.isActualInterval)(this._series.intervalObj().value(),this._properties.childs().intervalsVisibilities),e!==this._isActualInterval&&(this._onIsActualIntervalChange.fire(),this._visibleChanged(),this.processHibernate())}_visibleChanged(){this._series.invalidateBarColorerCache()}_getNonPriceParent(){const e=this._sources.value();for(const t of e)if(t instanceof us){const e=t.metaInfo();return e.is_price_study&&"Compare@tv-basicstudies"!==e.id?t._getNonPriceParent():t}return null}_updateInputValue(e,t){const s=this._properties.childs().inputs.childs();if(s[t.id])if("price"===t.type)s[t.id].setValue(e.price);else if("time"===t.type){const i=this._model.timeScale().indexToTimePoint(e.index);null!==i&&s[t.id].setValue(1e3*i)}}_initializeStudyInputsPaneViews(){}_updateCurrencySourceSymbolInfo(){null!==this._currencySourceSymbolInputProperty&&(this._currencySourceSymbolInfo=this._resolvedSymbolsByInput[this._currencySourceSymbolInputProperty.value()]??null)}_initializeCurrencySource(){const e=this.metaInfo(),t="symbolInputSymbolSource"===e.symbolSource?.type&&e.symbolSource?.inputId,s=e.inputs.find((e=>e.id===t));if("string"==typeof t&&"symbol"===s?.type&&e.is_price_study){const e=this._properties.childs().inputs.childs()[t];void 0!==e&&(e.subscribe(this,this._onCurrencyMayChange),this._currencySourceSymbolInputProperty=e)}}_recreatePaneViews(){this.hasBarColorer()&&this._model.mainSeries().invalidateBarStylesCache(),this._createViews(),this.recalculate(),this.updateAllViews((0,N.sourceChangeEvent)(this.id()))}async _pinePatchProps(){throw new Error("Not implemented")}_areStudyInputsModified(e){if(0===Object.keys(e).length)return!1;if(void 0===this._oldStudyInputs)return!0;const t=Object.keys(this._oldStudyInputs);(0, p.assert)(t.length===Object.keys(e).length,"keys quantity should be equal");for(const s of t)if((0,p.assert)(e.hasOwnProperty(s),`key '${s}' should exist in study inputs`),(0,p.ensureDefined)(this._oldStudyInputs)[s]!==e[s])return!0;return!1}_onVisibleTimeRangeInputsChanged(e){null!==e?this._updateVisibleTimeRangeInputs(e):this.isStarted()&&this._chartApi.isConnected().value()&&this.stop(!0)}_updateVisibleTimeRangeInputs(e,t=!0){const s={first_visible_bar_time:e.firstVisibleBarTime,last_visible_bar_time:e.lastVisibleBarTime,subscribeRealtime:e.subscribeRealtime},i=this.metaInfo().inputs,r=[];for(const e of i)s.hasOwnProperty(e.id)&&r.push(e.id);const n=this.properties().childs().inputs;for(const e of r)n.childs()[e].setValueSilently(s[e]);t&&r.length>0&&n.fireChanged()}_getStudyErrorText(e){const t=e.split(":",2)[0];return decodeURIComponent(t)}_priceScaleByProperties(){if("default"===this.properties().childs().precision.value())return null;const e=parseInt(this.properties().childs().precision.value());return isFinite(e)?Math.pow(10,e):null}_priceScaleByMetaInfo(){const e=this.metaInfo().format,t="inherit"!==e.type?e.precision:void 0,s=(0,_.isNumber)(t)?Math.pow(10,t):void 0;if("price"===e.type||"percent"===e.type)return s||100;if("volume"===e.type){if(void 0===e.precision){const e=this.series().symbolInfo();if(null!==e&&(0,_.isNumber)(e.volume_precision))return Math.pow(10,e.volume_precision)}return 1}return"inherit"===e.type||Gt.logWarn("Unsupported format type: "+e.type),null}_inputSymbols(){return this.metaInfo().inputs.filter((e=>"symbol"===e.type)).map((e=>(0,p.ensureDefined)(this._properties.childs().inputs.child(e.id)).value()))}_studySpec(e){return{id:this._metaInfo.value().id,child:e??this.isChildStudy(),fundamental:!1}}_onFormatterPropsChanged(){this._recreatePriceFormattingDependencies()}_setSources(e){this.invalidateTitleCache(),this._sources.setValue(e),this._onParentSourcesChanges.fire()}async _awaitForMetaInfo(){const e={resolver:()=>{}},t=()=>e.resolver();try{await Promise.race([new Promise(((e,t)=>{setTimeout((()=>t(new Error("Timeout"))),3e3)})),await new Promise((s=>{e.resolver=s,this.metaInfoWV().subscribe(t)}))])}catch(e){throw e}finally{this.metaInfoWV().unsubscribe(t)}}}},51752:(e,t,s)=>{s.d(t,{plotShapesData:()=>r});var i=s(11542);const r={shape_arrow_down:{guiName:i.t(null,void 0,s(34247)),id:"shape_arrow_down",paneRendererClass:"PaneRendererArrowDown",pineName:"shape.arrowdown",icon:"arrow_down"},shape_arrow_up:{guiName:i.t(null,void 0,s(45523)),id:"shape_arrow_up",paneRendererClass:"PaneRendererArrowUp",pineName:"shape.arrowup",icon:"arrow_up"},shape_circle:{guiName:i.t(null,void 0,s(91944)),id:"shape_circle",paneRendererClass:"PaneRendererCircleShape",pineName:"shape.circle",icon:"circle"},shape_cross:{guiName:i.t(null,void 0,s(6969)),id:"shape_cross",paneRendererClass:"PaneRendererCrossShape",pineName:"shape.cross",icon:"cross"},shape_diamond:{guiName:i.t(null,void 0,s(15179)),id:"shape_diamond",paneRendererClass:"PaneRendererDiamond",pineName:"shape.diamond",icon:"diamond"},shape_flag:{ guiName:i.t(null,void 0,s(33885)),id:"shape_flag",paneRendererClass:"PaneRendererFlagShape",pineName:"shape.flag",icon:"flag"},shape_label_down:{guiName:i.t(null,void 0,s(85924)),id:"shape_label_down",paneRendererClass:"PaneRendererLabelDown",pineName:"shape.labeldown",icon:"label_down"},shape_label_up:{guiName:i.t(null,void 0,s(49857)),id:"shape_label_up",paneRendererClass:"PaneRendererLabelUp",pineName:"shape.labelup",icon:"label_up"},shape_square:{guiName:i.t(null,void 0,s(66205)),id:"shape_square",paneRendererClass:"PaneRendererSquare",pineName:"shape.square",icon:"square"},shape_triangle_down:{guiName:i.t(null,void 0,s(76152)),id:"shape_triangle_down",paneRendererClass:"PaneRendererTriangleApexDown",pineName:"shape.triangledown",icon:"triangle_down"},shape_triangle_up:{guiName:i.t(null,void 0,s(21236)),id:"shape_triangle_up",paneRendererClass:"PaneRendererTriangleApexUp",pineName:"shape.triangleup",icon:"triangle_up"},shape_xcross:{guiName:i.t(null,void 0,s(11316)),id:"shape_xcross",paneRendererClass:"PaneRendererXCross",pineName:"shape.xcross",icon:"x_cross"}}}}]);