"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[5648],{25432:(e,t,i)=>{i.d(t,{commonLineToolPropertiesStateKeys:()=>r});const r=["symbolStateVersion","zOrderVersion","frozen","title","interval","symbol","currencyId","unitId","metricId","visible","adjustedToSplitTime","intervalsVisibilities.ticks","intervalsVisibilities.seconds","intervalsVisibilities.secondsFrom","intervalsVisibilities.secondsTo","intervalsVisibilities.minutes","intervalsVisibilities.minutesFrom","intervalsVisibilities.minutesTo","intervalsVisibilities.hours","intervalsVisibilities.hoursFrom","intervalsVisibilities.hoursTo","intervalsVisibilities.days","intervalsVisibilities.daysFrom","intervalsVisibilities.daysTo","intervalsVisibilities.weeks","intervalsVisibilities.weeksFrom","intervalsVisibilities.weeksTo","intervalsVisibilities.months","intervalsVisibilities.monthsFrom","intervalsVisibilities.monthsTo","intervalsVisibilities.ranges"];var s,o,n;!function(e){e[e.NotShared=0]="NotShared",e[e.SharedInLayout=1]="SharedInLayout",e[e.GloballyShared=2]="GloballyShared"}(s||(s={})),function(e){e.BeforeAllAction="BeforeAll",e.CustomAction="CustomAction"}(o||(o={})),function(e){e.FloatingToolbarButton="FloatingToolbarButton",e.Default="Default"}(n||(n={}))},41928:(e,t,i)=>{i.d(t,{LineSourcePaneView:()=>f,anchorResizeCursorType:()=>_,createLineSourcePaneViewPoint:()=>P});var r=i(11284),s=i(85842),o=i(29968),n=i(83077),a=i(71367),l=i(8165),c=i(28031),u=i(61208);const h=r.colorsPalette["color-tv-blue-600"];var d,p;function _(e,t){const i=e.x-t.x,r=e.y-t.y;if(!Number.isFinite(i)||!Number.isFinite(r)||0===i&&0===r)return c.PaneCursorType.Default;let o=Math.atan2(r,i);return o<0&&(o+=2*Math.PI),o>=p.deg337_5||o
=p.deg157_5&&o=p.deg22_5&&o=p.deg202_5&&o=p.deg67_5&&o=p.deg247_5&&o=p.deg112_5&&o=p.deg292_5&&o{const i=r[t],s=(0,l.lineSourcePaneViewPointToLineAnchorPoint)(e);return i&&(s.snappingPrice=i.price,s.snappingIndex=i.index),s}));e.append(this.createLineAnchor({...t,points:s},0))}createLineAnchor(e,t){const i=e.points.map((e=>e.point)),r=this._getOwnerSource();if(this.isLocked()){const s=this._getSelectionRenderer(t);return s.setData({bgColors:this._lineAnchorColors(i),points:e.points,visible:this.areAnchorsVisible(),hittestResult:n.HitTarget.Regular,ownerSourceId:r?.id(),barSpacing:this._model.timeScale().barSpacing()}),s}const s=(0,o.lastMouseOrTouchEventInfo)().isTouch,a=this._getLineAnchorRenderer(t),l=this.isHoveredSource()?this._model.lastHittestData()?.pointIndex??null:null;return a.setData({...e,color:this.anchorColor(),backgroundColors:this._lineAnchorColors(i),hoveredPointIndex:l,linePointBeingEdited:this.isBeingEdited()?this._model.linePointBeingEdited():null,radius:this._anchorRadius(),strokeWidth:s?d.TouchStrokeWidth:d.RegularStrokeWidth,selected:this.isSelectedSource(),selectedStrokeWidth:s?d.TouchSelectedStrokeWidth:d.RegularSelectedStrokeWidth,visible:this.areAnchorsVisible(),clickHandler:e.clickHandler,ownerSourceId:r?.id()}),a}_getOwnerSource(){return this._ownerSource??this._source.ownerSource()}_anchorRadius(){return(0,o.lastMouseOrTouchEventInfo)().isTouch?d.TouchAnchorRadius:d.RegularAnchorRadius}_lineAnchorColors(e){const t=(0,s.ensureNotNull)(this._model.paneForSource(this._source)).height();return e.map((e=>this._model.backgroundColorAtYPercentFromTop(e.y/t)))}_updateImpl(e){this._points=[];this._model.timeScale().isEmpty()||this._validatePriceScale()&&(this._source.points().forEach(((e,t)=>{const i=this._source.pointToScreenPoint(e,this._ownerSource??void 0);i&&this._points.push(P(i,t))})),2===this._points.length&&(this._middlePoint=this._source.calcMiddlePoint(this._points[0],this._points[1])),this._invalidated=!1)}_validatePriceScale(){const e=this._getOwnerSource()?.priceScale();return null!=e&&!e.isEmpty()}_getSource(){return this._source}_getPoints(){return this._points}_getModel(){return this._model}_height(){const e=this._getOwnerSource()?.priceScale();return null!=e?e.height():0}_width(){return this._model.timeScale().width()}_needLabelExclusionPath(e,t){const i=this._source.properties().childs()
;return"middle"===(t??i.vertLabelsAlign.value())&&(0,u.needTextExclusionPath)(e)}_addAlertRenderer(e,t,i=this._source.properties().linecolor.value()){}_getAlertRenderer(e){return null}_getSelectionRenderer(e){for(;this._selectionRenderers.length<=e;)this._selectionRenderers.push(new a.SelectionRenderer);return this._selectionRenderers[e]}_getLineAnchorRenderer(e){for(;this._lineAnchorRenderers.length<=e;)this._lineAnchorRenderers.push(new l.LineAnchorRenderer);return this._lineAnchorRenderers[e]}}},86371:(e,t,i)=>{i.d(t,{LineDataSourceProperty:()=>l});var r=i(57600),s=i(35558),o=i(85842),n=i(93445),a=i(47895);class l extends n.DefaultProperty{constructor({templateKeys:e,factoryDefaultsSupplier:t,...i}){let r=t;t&&(r=()=>{const e=t();return(0,a.applyDefaultsOverrides)(e,void 0,void 0,i.defaultName),e}),super({saveNonDefaultUserPreferencesOnly:!0,factoryDefaultsSupplier:r,...i}),this._templateKeys=(0,o.ensureDefined)(e||this._allDefaultsKeys)}template(){return(0,n.extractState)(this.state(),this._templateKeys,[])}applyTemplate(e){this.mergeAndFire((0,n.extractState)((0,s.default)((0,r.default)(this._factoryDefaultsSupplier()),e),this._templateKeys))}}},57651:(e,t,i)=>{i.d(t,{LineToolRiskRewardLongPropertiesImpl:()=>b,LineToolRiskRewardShortPropertiesImpl:()=>L,roundValue:()=>w,setNumberPropertyValueNaNSafe:()=>R});var r=i(49084),s=i(85842),o=i(47097),n=i(86684),a=i(93445),l=i(17567),c=i(88483),u=i(25432),h=i(86371),d=i(22496);const p={intervalsVisibilities:{...c.intervalsVisibilitiesDefaults},linewidth:1,fontsize:12,compact:!1,riskDisplayMode:d.RiskDisplayMode.Percentage,accountSize:1e3,lotSize:1,risk:25,leverage:1e4,alwaysShowStats:!1,showPriceLabels:!0,qtyPrecision:"default",currency:"NONE",infoBlocks:{tpPriceOffset:{visible:!0},tpPercentOffset:{visible:!0},tpTickOffset:{visible:!0},tpAmount:{visible:!0},tpPL:{visible:!1},openClosePL:{visible:!0},qty:{visible:!0},riskRewardRatio:{visible:!0},slPriceOffset:{visible:!0},slPercentOffset:{visible:!0},slTickOffset:{visible:!0},slAmount:{visible:!0},slPL:{visible:!1}}},_={linecolor:n.colors.colorColdGray500,textcolor:n.colors.colorWhite,stopBackground:n.colors.colorRipeRed500Alpha20,profitBackground:n.colors.colorMintyGreen500Alpha20,stopBackgroundTransparency:80,profitBackgroundTransparency:80},P=new Map([[o.StdTheme.Light,_],[o.StdTheme.Dark,_]]),f=(0,a.extractThemedColors)((0,s.ensureDefined)(P.get(o.StdTheme.Light)),(0,s.ensureDefined)(P.get(o.StdTheme.Dark))),g=(0,a.extractAllPropertiesKeys)((0,s.ensureDefined)(P.get(o.StdTheme.Light))),S=(0,a.extractAllPropertiesKeys)(p),v=[...new Set([...g,...S,...u.commonLineToolPropertiesStateKeys]),"stopLevel","profitLevel","qty","amountTarget","amountStop","entryPointCurrencyRate","closePointCurrencyRate"],y=[...new Set([...g,...S]),"stopLevel","profitLevel"];class m extends h.LineDataSourceProperty{constructor(e){super(e),this.hasChild("entryPointCurrencyRate")||this.addProperty("entryPointCurrencyRate",1),this.hasChild("closePointCurrencyRate")||this.addProperty("closePointCurrencyRate",1),
this.hasChild("stopLevel")||this.addProperty("stopLevel",0),this.hasChild("profitLevel")||this.addProperty("profitLevel",0),this.hasChild("riskSize")||this.addProperty("riskSize",0),this.hasChild("qty")||this.addProperty("qty",0),this.hasChild("amountTarget")||this.addProperty("amountTarget",this.childs().accountSize.value()),this.hasChild("amountStop")||this.addProperty("amountStop",this.childs().accountSize.value())}static _create(e,t,i){return i&&(i.entryPrice&&(0,r.default)(i.entryPrice)&&(i.entryPrice=0),i.stopPrice&&(0,r.default)(i.stopPrice)&&(i.stopPrice=0),i.targetPrice&&(0,r.default)(i.targetPrice)&&(i.targetPrice=0)),new this({defaultName:e,factoryDefaultsSupplier:()=>(0,l.factoryDefaultsForCurrentTheme)(p,P),nonThemedDefaultsKeys:S,themedDefaultsKeys:g,allStateKeys:v,themedColors:f,templateKeys:y,replaceThemedColorsOnThemeChange:!0,state:i,theme:t})}}class b extends m{static create(e,t){return m._create("linetoolriskrewardlong",e,t)}}class L extends m{static create(e,t){return m._create("linetoolriskrewardshort",e,t)}}function w(e){return parseFloat(e.toFixed(2))}function R(e,t){(Number.isFinite(t)||Number.isFinite(e.value()))&&e.setValue(t)}},24427:(e,t,i)=>{i.d(t,{LineToolRiskRewardBase:()=>ae,registerReversibleTool:()=>oe});var r=i(83991),s=i(85842),o=i(7321),n=i(91599),a=i(55531),l=i(47166),c=i(44850),u=i(43459),h=i(82014),d=i(54951),p=i(9840),_=i(64013),P=i(10308),f=i(72769),g=i(89659),S=i(75323),v=i(65366),y=i(22384);class m extends y.Property{constructor(e,t){super(),this._lineSource=e,this._pointIndex=t}value(){const e=this._lineSource.points(),t=e[this._pointIndex]?e[this._pointIndex].price:this._lineSource.normalizedPoints()[this._pointIndex].price;return this._formatAndParsePrice(t)}state(){return this.value()}merge(e,t){return this.setValue(e),t?[]:null}_formatAndParsePrice(e){const t=(0,s.ensureNotNull)(this._lineSource.ownerSource()),i=t.defaultFormatter?.()||t.formatter();if(i.parse){const t=i.format(e),r=i.parse(t);return r.res?r.value:e}return e}}class b extends m{constructor(e){super(e,0)}setValue(e){if(this._lineSource.isSourceHidden()){const t=this._lineSource.normalizedPoints();return t[this._pointIndex].price=parseFloat(e.toString()),void this._lineSource.restorePoints(t,[])}const t=this._lineSource.points()[this._pointIndex];this._lineSource.startChanging(this._pointIndex,t),t.price=parseFloat(e.toString()),this._lineSource.setPoint(this._pointIndex,t),this._lineSource.recalculate(),this._lineSource.model().updateSource(this._lineSource),this._listeners.fire(this,""),this._lineSource.endChanging(!1,!1),this._lineSource.syncPriceLevels()}}class L extends m{constructor(e){super(e,1)}value(){const e=this._lineSource.stopPrice();return this._formatAndParsePrice(e)}setValue(e){const t=Math.round(Math.abs(e-this._lineSource.entryPrice())*this._lineSource.ownerSourceBase());this._lineSource.properties().childs().stopLevel.setValue(t),this._lineSource.syncPriceLevels()}}class w extends m{constructor(e){super(e,2)}value(){const e=this._lineSource.profitPrice()
;return this._formatAndParsePrice(e)}setValue(e){const t=Math.round(Math.abs(e-this._lineSource.entryPrice())*this._lineSource.ownerSourceBase());this._lineSource.properties().childs().profitLevel.setValue(t),this._lineSource.syncPriceLevels()}}var R,x=i(22496);!function(e){e[e.Entry=0]="Entry",e[e.Close=1]="Close",e[e.ActualEntry=2]="ActualEntry",e[e.ActualClose=3]="ActualClose"}(R||(R={}));var T=i(15269),k=i(82347);class C extends T.PriceAxisView{constructor(e,t){super(),this._source=e,this._data=t}_updateRendererData(e,t,i){if(e.visible=!1,!this._showAxisLabel())return;const r=this._source.priceScale();if(0===this._source.points().length||null===r||r.isEmpty())return;const s=this._source.ownerSource(),o=null!==s?s.firstValue():null;if(null===o)return;const n=this._data.priceProperty.value(),a=(0,k.resetTransparency)(this._data.colorProperty.value());i.background=a,i.textColor=this.generateTextColor(a),i.coordinate=r.priceToCoordinate(n,o),e.text=r.formatPrice(n,o),e.visible=!0,e.selectedMarkColor=this._source.model().selection().isSelected(this._source)?a:void 0}_showAxisLabel(){return this._source.properties().childs().showPriceLabels.value()||this._source.model().selection().isSelected(this._source)}}var A=i(57415),M=i(41928),V=i(95385),I=i(6353),B=i(61208),N=i(6938),D=i(83077),E=i(99680),z=i(34192),O=i(68459),F=i(81458),H=i(28031),W=i(95397),q=i(14491),K=i(80140),Q=i(8165);const Y=n.t(null,{context:"line_tool_position"},i(40569)),U=n.t(null,{context:"line_tool_position"},i(45341)),X=n.t(null,{context:"line_tool_position"},i(32102)),G=n.t(null,{context:"line_tool_position"},i(93691)),$=n.t(null,{context:"line_tool_position"},i(30154)),j=n.t(null,{context:"line_tool_position"},i(83092)),Z=n.t(null,{context:"line_tool_position"},i(19404)),J=n.t(null,{context:"line_tool_position"},i(82696)),ee=n.t(null,{context:"line_tool_position"},i(54014));function te(e){return e.value()??NaN}class ie extends M.LineSourcePaneView{constructor(){super(...arguments),this._entryLineRenderer=new I.TrendLineRenderer,this._stopLineRenderer=new I.TrendLineRenderer,this._targetLineRenderer=new I.TrendLineRenderer,this._positionLineRenderer=new I.TrendLineRenderer,this._fullStopBgRenderer=new N.RectangleRenderer,this._stopBgRenderer=new N.RectangleRenderer,this._fullTargetBgRenderer=new N.RectangleRenderer,this._targetBgRenderer=new N.RectangleRenderer,this._stopLabelRenderer=new B.TextRenderer,this._middleLabelRenderer=new B.TextRenderer,this._profitLabelRenderer=new B.TextRenderer,this._renderer=new E.CompositeRenderer}isLabelVisible(){return this.isHoveredSource()||this.isSelectedSource()||this._source.properties().childs().alwaysShowStats.value()}renderer(e){return this._invalidated&&this._updateImpl(e),this._renderer}_updateImpl(e){super._updateImpl(e),this._renderer.clear();const t=this._model.timeScale(),i=this._source.priceScale();if(!i||i.isEmpty()||t.isEmpty())return;const r=this._source.points();if(r.length<2||this._points.length<2)return;const o=(0,s.ensureNotNull)(this._source.ownerSource()),n=o?.barsProvider().bars()
;if(!n||n.isEmpty())return;if(null===n.last())return;const a=4===r.length,l=this._source.lastBarData();if(!l)return;const c=l.closePrice,u=this._source.stopPrice(),h=this._source.profitPrice(),d=this._source.calculatePL(c),p=o.symbolSource().symbolInfo();if(!p)return;const _=o.firstValue();if(null===_)return;const P=this._points[R.Entry].y,f=i.priceToCoordinate(u,_),g=i.priceToCoordinate(h,_),S=i.priceToCoordinate(l.closePrice,_),v=t.indexToCoordinate(l.index),y=this._points[R.Entry].x,m=this._points[R.ActualEntry]?this._points[R.ActualEntry].x:this._points[R.Close].x,b=this._points[R.ActualClose]?this._points[R.ActualClose].x:this._points[R.Close].x,L=this._points[R.Close].x,w=this._source.entryPrice(),x=this._source.properties().childs(),T=te(x.qty),k=x.targetPrice.value(),C={pl:d,isClosed:a,entryLevel:P,stopLevel:f,profitLevel:g,closeLevel:S,closeBar:v,left:y,entryX:m,right:b,edge:L,entryPrice:w,stopPrice:u,profitPrice:h,currentPrice:c,slPL:this._source.calculatePLForSL(u,w,T),tpPL:this._source.calculatePLForTP(k,w,T)},{mediaSize:{width:M,height:V}}=e;let I=L<-5||y>M+5;if(this._createBackgroundRenderers(C,this._renderer),this._createLinesRenderers(C,this._renderer),this._createLabelsRenderers(C,this._renderer,p,(0,z.getPipFormatter)(p)),I=[this._profitLabelRenderer,this._stopLabelRenderer,this._middleLabelRenderer].reduce(((e,t)=>e&&t.isOutOfScreen(M,V)),I),I)return;const[B]=this._points,N=[(0,Q.lineSourcePaneViewPointToLineAnchorPoint)(new A.Point(y,B.y),0,void 0,void 0,void 0,w),(0,Q.lineSourcePaneViewPointToLineAnchorPoint)(new A.Point(L,B.y),1,H.PaneCursorType.HorizontalResize,!0,void 0,void 0,l.index),(0,Q.lineSourcePaneViewPointToLineAnchorPoint)(new A.Point(y,f),2,H.PaneCursorType.VerticalResize,!0,void 0,u),(0,Q.lineSourcePaneViewPointToLineAnchorPoint)(new A.Point(y,g),3,H.PaneCursorType.VerticalResize,!0,void 0,h)];this._renderer.append(this.createLineAnchor({points:N},0))}_createBackgroundRenderers(e,t){const i=this._source.properties().childs();{const t={points:[new A.Point(e.left,e.entryLevel),new A.Point(e.edge,e.stopLevel)],color:"white",linewidth:0,backcolor:i.stopBackground.value(),fillBackground:!0,transparency:i.stopBackgroundTransparency.value(),extendLeft:!1,extendRight:!1,backgroundHitTarget:D.HitTarget.MovePoint};this._fullStopBgRenderer.setData(t),this._renderer.append(this._fullStopBgRenderer)}if(e.pl<0&&e.entryX!==e.right){const t=new A.Point(e.entryX,e.entryLevel),r=new A.Point(e.right,e.closeLevel),s=.01*i.stopBackgroundTransparency.value(),o=100-100*(1-s*s*s),n={points:[t,r],color:"white",linewidth:0,backcolor:i.stopBackground.value(),fillBackground:!0,transparency:o,extendLeft:!1,extendRight:!1,backgroundHitTarget:D.HitTarget.MovePoint};this._stopBgRenderer.setData(n),this._renderer.append(this._stopBgRenderer)}{const t={points:[new A.Point(e.left,e.entryLevel),new A.Point(e.edge,e.profitLevel)],color:"white",linewidth:0,backcolor:i.profitBackground.value(),fillBackground:!0,transparency:i.profitBackgroundTransparency.value(),extendLeft:!1,extendRight:!1,
backgroundHitTarget:D.HitTarget.MovePoint};this._fullTargetBgRenderer.setData(t),this._renderer.append(this._fullTargetBgRenderer)}if(e.pl>0&&e.entryX!==e.right){const t=new A.Point(e.entryX,e.entryLevel),r=new A.Point(e.right,e.closeLevel),s=.01*i.profitBackgroundTransparency.value(),o=100-100*(1-s*s*s),n={points:[t,r],color:"white",linewidth:0,backcolor:i.profitBackground.value(),fillBackground:!0,transparency:o,extendLeft:!1,extendRight:!1,backgroundHitTarget:D.HitTarget.MovePoint};this._targetBgRenderer.setData(n),this._renderer.append(this._targetBgRenderer)}}_createLinesRenderers(e,t){const i=this._source.properties().childs(),r=(e,t,r,s)=>{const o={points:[t,r],color:s??i.linecolor.value(),linewidth:i.linewidth.value(),linestyle:K.LINESTYLE_SOLID,extendleft:!1,extendright:!1,leftend:O.LineEnd.Normal,rightend:O.LineEnd.Normal};e.setData(o),this._renderer.append(e)};if(this._points[R.ActualEntry]){const t={points:[this._points[R.ActualEntry],e.isClosed?this._points[R.ActualClose]:new A.Point(e.closeBar,e.closeLevel)],color:this._source.properties().childs().linecolor.value(),linewidth:1,linestyle:K.LINESTYLE_DASHED,extendleft:!1,extendright:!1,leftend:O.LineEnd.Normal,rightend:O.LineEnd.Arrow};this._positionLineRenderer.setData(t),this._renderer.append(this._positionLineRenderer)}{const t=new A.Point(e.left,this._points[R.Entry].y),i=new A.Point(e.edge,this._points[R.Entry].y);r(this._entryLineRenderer,t,i)}{const t=new A.Point(e.left,e.stopLevel),s=new A.Point(e.edge,e.stopLevel);r(this._stopLineRenderer,t,s,i.stopBackground.value())}{const t=new A.Point(e.left,e.profitLevel),s=new A.Point(e.edge,e.profitLevel);r(this._targetLineRenderer,t,s,i.profitBackground.value())}}_addCenterLabel(e,t,i){const r=this._source.properties().childs(),s={font:q.CHART_FONT_FAMILY,offsetX:3,horzAlign:"center",backgroundRoundRect:4,boxPaddingHorz:4,points:[i.p],text:i.txt,color:r.textcolor.value(),offsetY:i.offsetY,vertAlign:i.vertAlign,backgroundColor:(0,k.resetTransparency)(i.color),fontsize:r.fontsize.value(),borderColor:i.border};return t.setData(s),e.append(t),s}_createMiddleLabel(e,t,i){const{entryPrice:r,profitPrice:o,stopPrice:n,currentPrice:a,pl:l,left:c,edge:u,isClosed:h}=e,d=Math.abs(r-o)/Math.abs(r-n),p=this._source.properties().childs(),_=(0,s.ensureNotNull)(this._source.ownerSource()),P=new A.Point((c+u)/2,Math.round(this._points[0].y));let f="",g="";const S=(0,z.getNumericFormatter)().format(Math.round(100*d)/100);if(this._points[1]){const e=_.formatter();if(e.formatChange){const t=Math.max(a,r),i=Math.min(a,r);g=l>=0?e.formatChange(t,i):e.formatChange(i,t)}else g=e.format(l)}const v=te(p.qty)/p.lotSize.value(),y=this._roundQty(v,i),m=p.infoBlocks.childs();if(p.compact.value())m.openClosePL.childs().visible.value()&&(f+=g),m.qty.childs().visible.value()&&(""!==f&&(f+=" ~ "),f+=y),m.riskRewardRatio.childs().visible.value()&&(""!==f&&(f+="\n"),f+=S);else{if(m.openClosePL.childs().visible.value()){const e=h?G:X;f+=g?Y.format({status:e,pnl:g}):""}m.qty.childs().visible.value()&&(""!==f&&(f+=", "),f+=ee.format({
qty:y.toString()})),m.riskRewardRatio.childs().visible.value()&&(""!==f&&(f+="\n"),f+=$.format({ratio:S}))}let b=p.linecolor.value();return l<0?b=p.stopBackground.value():l>0&&(b=p.profitBackground.value()),""===f?null:this._addCenterLabel(t,this._middleLabelRenderer,{p:P,txt:f,color:b,vertAlign:V.VerticalAlign.Middle,offsetY:0,border:"white"})}_createStopLabel(e,t,i){const{stopPrice:r,entryPrice:o,left:n,edge:a,stopLevel:l,slPL:c}=e,u=this._source.properties().childs(),h=u.infoBlocks.childs(),d=(0,s.ensureNotNull)(this._source.ownerSource()),p=Math.abs(r-o),_=Math.pow(10,3),P=Math.round(100*_*p/o)/_,f=new A.Point((n+a)/2,l);let g="";const S=d.formatter(),v=S.formatChange?.(Math.max(r,o),Math.min(r,o))??S.format(p),y=(0,z.getPercentageFormatter)(3).format(P);if(u.compact.value()){if(h.slPriceOffset.childs().visible.value()&&(g+=v),h.slPercentOffset.childs().visible.value()){let e=!1;""!==g&&(e=!0,g+=" "),g+=e?`(${y})`:y}h.slTickOffset.childs().visible.value()&&i&&(""!==g&&(g+=" "),g+=i.format(p)),h.slAmount.childs().visible.value()&&(""!==g&&(g+=" "),g+=te(u.amountStop)),h.slPL.childs().visible.value()&&(""!==g&&(g+=" "),g+=S.format(c))}else{if(h.slPriceOffset.childs().visible.value()&&(g+=j.format({stopChange:(0,F.forceLTRStr)(v)})),h.slPercentOffset.childs().visible.value()){let e=!1;""!==g&&(e=!0,g+=" "),g+=(0,F.forceLTRStr)(e?`(${y})`:y)}h.slTickOffset.childs().visible.value()&&i&&(""!==g&&(g+=" "),g+=(0,F.forceLTRStr)(i.format(p))),h.slAmount.childs().visible.value()&&(""!==g&&(g+=", "),g+=J.format({amount:(0,F.forceLTRStr)(te(u.amountStop).toString())})),h.slPL.childs().visible.value()&&(""!==g&&(g+=", "),g+=U.format({pnl:(0,F.forceLTRStr)(S.format(c))}))}const m=this._model.mainSeries().priceScale().isInverted()?-1:1;return""===g?null:this._addCenterLabel(t,this._stopLabelRenderer,{p:f,txt:g,color:u.stopBackground.value(),vertAlign:m*(o-r)<0?V.VerticalAlign.Bottom:V.VerticalAlign.Top,offsetY:0})}_createTargetLabel(e,t,i){const{profitPrice:r,entryPrice:o,stopPrice:n,left:a,edge:l,profitLevel:c,tpPL:u}=e,h=this._source.properties().childs(),d=h.infoBlocks.childs(),p=(0,s.ensureNotNull)(this._source.ownerSource()),_=Math.abs(r-o),P=Math.pow(10,3),f=Math.round(100*P*_/o)/P,g=new A.Point((a+l)/2,c);let S="";const v=p.formatter(),y=v.formatChange?.(Math.max(r,o),Math.min(r,o))??v.format(_),m=(0,z.getPercentageFormatter)(3).format(f);if(h.compact.value()){if(d.tpPriceOffset.childs().visible.value()&&(S+=y),d.tpPercentOffset.childs().visible.value()){let e=!1;""!==S&&(e=!0,S+=" "),S+=e?`(${m})`:m}d.tpTickOffset.childs().visible.value()&&i&&(""!==S&&(S+=" "),S+=i.format(_)),d.tpAmount.childs().visible.value()&&(""!==S&&(S+=" "),S+=te(h.amountTarget)),d.tpPL.childs().visible.value()&&(""!==S&&(S+=" "),S+=v.format(u))}else{if(d.tpPriceOffset.childs().visible.value()&&(S+=Z.format({profitChange:(0,F.forceLTRStr)(y)})),d.tpPercentOffset.childs().visible.value()){let e=!1;""!==S&&(e=!0,S+=" "),S+=(0,F.forceLTRStr)(e?`(${m})`:m)}d.tpTickOffset.childs().visible.value()&&i&&(""!==S&&(S+=" "),S+=(0,F.forceLTRStr)(i.format(_))),
d.tpAmount.childs().visible.value()&&(""!==S&&(S+=", "),S+=J.format({amount:(0,F.forceLTRStr)(te(h.amountTarget).toString())})),d.tpPL.childs().visible.value()&&(""!==S&&(S+=", "),S+=U.format({pnl:(0,F.forceLTRStr)(v.format(u))}))}const b=this._model.mainSeries().priceScale().isInverted()?-1:1;return""===S?null:this._addCenterLabel(t,this._profitLabelRenderer,{p:g,txt:S,color:h.profitBackground.value(),vertAlign:b*(o-n)<0?V.VerticalAlign.Top:V.VerticalAlign.Bottom,offsetY:0})}_createLabelsRenderers(e,t,i,r){if(!this.isLabelVisible())return;const o=this._createMiddleLabel(e,t,i),n=this._createStopLabel(e,t,r),a=this._createTargetLabel(e,t,r),l=[this._profitLabelRenderer,this._stopLabelRenderer,this._middleLabelRenderer].reduce(((e,t)=>Math.max(e,t.measure().width)),0),c=e.edge-e.left,u=this._anchorRadius();if(c-l-u<=8&&(a&&(a.offsetY+=u+8,this._profitLabelRenderer.setData(a)),n&&(n.offsetY+=u+8,this._stopLabelRenderer.setData(n)),o)){let t;if(this._source.priceScale()?.isLog()){const i=Math.abs(this._points[0].y-e.stopLevel);t=Math.abs(this._points[0].y-e.profitLevel)>i?-1:1}else{const i=Math.abs(e.stopPrice-e.entryPrice);t=Math.abs(e.profitPrice-e.entryPrice)>i?-1:1}const i=e.profitLevel"account_currency"===e.id)),l=i.childs().currency.value();n&&!n.options.includes(l)&&i.childs().currency.setValue(n.defval),n&&i.childs().currency.subscribe(this,this._updateStudySource),this.version=2;const{stopLevel:c,profitLevel:h}=i.childs();r||0!==c?.value()||0!==h?.value()||this.ownerSourceChanged().subscribe(this,(()=>{const e=(0,s.ensureNotNull)(t.timeScale().visibleBarsStrictRange()),i=(0,s.ensureNotNull)(t.timeScale().logicalRange()),r=e.firstBar(),o=e.lastBar(),n=(0,s.ensureNotNull)(this.ownerSource()),a=n.priceScale();if(a){const e={startTimePoint:r,endTimePoint:o,logicStartPoint:i.left(),logicEndPoint:i.right(),targetPriceScale:a,scaleSeriesOnly:a?.isScaleSeriesOnly()};let t=(0,s.ensureNotNull)(n.priceRange(e));if(a.isLog()){
const e=a.logicalToPrice(t.minValue()),i=a.logicalToPrice(t.maxValue());t=new u.PriceRange(e,i)}this._calculator.autoAdjustToPriceRange(t)}}),!0);const d=i.childs();i.addChild("entryPrice",new b(this)),i.addChild("stopPrice",new L(this)),i.addChild("targetPrice",new w(this)),this._calculator=new e(i,{syncPriceLevels:this.syncPriceLevels.bind(this),points:()=>this.points(),pointsWithInterval:()=>this._points,timePoints:()=>this._timePoint,assignPoints:e=>this._points=e,interval:()=>this._model.mainSeries().interval(),bars:()=>this.ownerSource()?.barsProvider()?.bars()??new a.PlotList,ownerSourcePointValue:this._ownerSourcePointValue.bind(this),ownerSourceBase:this.ownerSourceBase.bind(this)}),this.ownerSourceChanged().subscribe(null,((e,t)=>{e&&e.barsProvider().dataUpdated().unsubscribeAll(this),t&&t.barsProvider().dataUpdated().subscribe(this,this._onSeriesUpdated)})),this.pointAdded().subscribe(this,(e=>{switch(e){case R.Entry:case R.Close:this._calculator.recalculateRiskSize(),this._calculator.recalculateQty()}this._updateStudySource()})),this.pointChanged().subscribe(this,(e=>{switch(e){case R.Entry:case R.Close:this._calculator.recalculateRiskSize(),this._calculator.recalculateQty()}this._updateStudySource()})),d.riskDisplayMode.value()===x.RiskDisplayMode.Percentage&&d.risk.value()>100&&d.riskDisplayMode.setValueSilently(x.RiskDisplayMode.Money),this._entryPriceAxisView=new C(this,{colorProperty:d.linecolor,priceProperty:d.entryPrice}),this._stopPriceAxisView=new C(this,{colorProperty:d.stopBackground,priceProperty:d.stopPrice}),this._profitPriceAxisView=new C(this,{colorProperty:d.profitBackground,priceProperty:d.targetPrice}),this._setPaneViews([new ie(this,t)]),i.onRestoreFactoryDefaults().subscribe(this,this._handleRestoringFactoryDefaults),this._symbolSourceSymbolInfo.subscribe(this._updatePriceLevelsIfNeeded.bind(this))}destroy(){this.ownerSource()?.barsProvider().dataUpdated().unsubscribeAll(this),this.ownerSourceChanged().unsubscribeAll(this),this._studySource?.destroy(),super.destroy()}availableCurrencies(){const e=(0,s.ensureDefined)(this._metaInfo?.inputs.find((e=>"account_currency"===e.id)));return(0,s.ensureDefined)(e.options)}setOwnerSource(e){super.setOwnerSource(e);const t=this.ownerSource();t&&t.symbolSource().symbolInfo()&&(this._calculator.recalculateAmount(),this._calculator.recalculateRiskSize(),this._calculator.recalculateQty())}state(e){const t=super.state(e);return this._actualOwnerSourceBase&&(t.ownerSourceBase=this._actualOwnerSourceBase),t}restoreData(e,t){this._restoredOwnerSourceBase=this._actualOwnerSourceBase=e.ownerSourceBase??null,this._updatePriceLevelsIfNeeded()}pointsCount(){return 2}priceAxisPoints(){if(!this._points.length)return[];const e=this._points[0],t=this._properties.childs();return[{...e,price:t.stopPrice.value()},{...e,price:t.entryPrice.value()},{...e,price:t.targetPrice.value()}]}priceAxisViews(e,t){
return this.isSourceHidden()||t!==this.priceScale()||this._model.paneForSource(this)!==e?null:[this._entryPriceAxisView,this._stopPriceAxisView,this._profitPriceAxisView]}updateAllViews(e){this.isActualSymbol()&&this.properties().childs().visible.value()&&((0,d.hideAllDrawings)().value()&&this.userEditEnabled()||(super.updateAllViews(e),this._entryPriceAxisView.update(e),this._stopPriceAxisView.update(e),this._profitPriceAxisView.update(e)))}migrateVersion(e,t,i){if(1===e&&this._points.length>=1){const e=[];e.push(this._points[0]);let t=this._points[0];if(t={price:t.price,index:this._getClosePointIndex(t.index),interval:this._properties.childs().interval.value()},e.push(t),this._points[1]&&e.push(this._points[1]),this._points[2]&&e.push(this._points[2]),this._points=e,this._timePoint.length>=1){const t=[],i=this._timePoint[0];t.push(i);const r={price:i.price,time_t:i.time_t,offset:this._getClosePointIndex(i.offset)};t.push(r),this._timePoint[1]&&e.push(this._points[1]),this._timePoint[2]&&e.push(this._points[2]),this._timePoint=t}}}restoreExternalState(e){if(!(0,o.isNumber)(e.entryPrice))return void super.restoreExternalState(e);let t;if(this.isActualSymbol())t=e;else{const{entryPrice:i,...r}=e,[s]=this._timePoint;s.price=i,t=r}this.properties().merge(t)}addPoint(e,t,i){e.price=this._roundPrice(e.price),super.addPoint(e,void 0,!0);const r={price:e.price,index:this._getClosePointIndex(e.index)};super._addPointIntenal(r,void 0,!0);const s=this._calculator.calculateActualEntry(e,r);if(s){super._addPointIntenal(s,void 0,!0);const e=this._calculator.findClosePoint(s,r);e&&super._addPointIntenal(e,void 0,!0)}return this._lastPoint=null,this._normalizePoints(),this.createServerPoints(),!0}setPoint(e,t,i,r){if(this.isSourceHidden())return;const s=this.properties().childs();switch(this._muteSyncLineStyle(),e){case 0:this._changeEntryPoint({...t,interval:this._model.mainSeries().interval()});break;case 2:s.stopPrice.setValue(this.prepareStopPrice(t.price));break;case 3:s.targetPrice.setValue(this.prepareProfitPrice(t.price));break;case 1:t.price=this._points[0].price,super.setPoint(1,t),this.recalculate()}this._unmuteSyncLineStyleWithoutApplyingChanges(),r||this.syncPriceLevels()}getPoint(e){if(this.isSourceHidden())return null;switch(e){case 0:return this._points[0];case 1:return{index:this._points[1].index,price:this._points[0].price};case 2:return{index:this._points[0].index,price:this.stopPrice()};case 3:return{index:this._points[0].index,price:this.profitPrice()}}return null}setPoints(e){this.isSourceHidden()||(this._muteSyncLineStyle(),super.setPoints(e),this.recalculate(),this._unmuteSyncLineStyleWithoutApplyingChanges(),this.syncPriceLevels())}start(){super.start(),this.recalculate()}startMoving(e,t,i,r){const o=(0,s.ensureDefined)(e.logical);o.price=this._roundPrice(o.price),super.startMoving(e,t,i)}move(e,t,i,r){const o=(0,s.ensureDefined)(e.logical);o.price=this._roundPrice(o.price),super.move(e,t,i),this.recalculate(),this._entryPriceAxisView.update((0,p.sourceChangeEvent)(this.id()))}axisPoints(){
if(!this._points[R.ActualEntry])return[];const e=this._points[R.ActualEntry];let t=null;if(4===this._points.length)t=this._points[R.ActualClose];else{const e=this.lastBarData();if(!e)return[];t={index:e.index,price:e.closePrice}}return[e,t]}recalculateStateByData(){this.recalculate()}recalculate(){this._calculator.recalculate()}syncPriceLevels(){if(!this.ownerSource())return;const e=this.linkKey().value();if(e){const t=this.properties().childs();this._syncLineStyleChanges(e,{entryPrice:t.entryPrice.value(),stopLevel:t.stopLevel.value(),profitLevel:t.profitLevel.value()})}}entryPrice(){return this._calculator.entryPrice()}profitPrice(){return this._calculator.profitPrice()}stopPrice(){return this._calculator.stopPrice()}calculatePL(e){return this._calculator.calculatePL(e)}calculatePLForTP(e,t,i){const r=this._ownerSourcePointValue();return this._calculator.calculatePLForTP(e,t,i,r)}calculatePLForSL(e,t,i){const r=this._ownerSourcePointValue();return this._calculator.calculatePLForSL(e,t,i,r)}lastBarData(){const e=this.ownerSource()?.barsProvider();if(!e)return null;const t=e.bars().firstIndex(),i=e.bars().lastIndex();if(null===t||null===i||isNaN(t)||isNaN(i))return null;const r=this.points();if(4===r.length){const e=r[R.ActualClose];return e.index{const t=ne.format({tool:(0,S.getTranslatedStringForSource)(v.TitleDisplayTarget.StatusLine,this)});e.beginUndoMacro(t);const i=function(e,t){const i=e.points(),r=e.zorder(),o=(0,s.ensureNotNull)(t.model().paneForSource(e)),n=(0,s.ensureNotNull)(e.ownerSource()),a=(0,s.ensureDefined)(se.get(e.toolname)),c=a.propertiesFactory(t.model().backgroundTheme().spawnOwnership(),e.properties().state()),u=e.linkKey().value(),h=u?_.CreateLineToolSyncMode.ForceOn:_.CreateLineToolSyncMode.ForceOff,d=t.createLineTool({pane:o,point:i[0],linkKey:u?(0,l.randomHash)():void 0,linetool:a.targetToolName,properties:c,ownerSource:n,synchronizationMode:h,sharingMode:e.sharingMode().value()});return d&&(t.startChangingLinetool(d,(0,s.ensureNotNull)(d.ownerSource()),d.points()[1],1),t.changeLinePoint(i[1]),t.endChangingLinetool(!1),t.insertBefore([d],e),d.setZorder(r)),t.removeSource(e,!1),d}(this,e);e.endUndoMacro(),i&&e.model().selectionMacro((e=>{e.addSourceToSelection(i,null)
}))}}})],placement:"CustomAction"}}_ignoreSourceEvent(e){return super._ignoreSourceEvent(e)&&e.sourceId!==this._model.mainSeries().id()}_applyTemplateImpl(e){const{targetPrice:t,stopPrice:i,entryPrice:r,...s}=e;super._applyTemplateImpl(s);const o=this.properties().childs();void 0!==e.stopLevel&&o.stopLevel.setValue(e.stopLevel),void 0!==e.profitLevel&&o.profitLevel.setValue(e.profitLevel)}_correctPoints(e,t){if(!this.isActualSymbol())return!1;const i=super._correctPoints(e.slice(0,this.pointsCount()),t);for(let t=0;tMath.max(this._points[0].index,this._points[1].index)||this.recalculateStateByData()}_getClosePointIndex(e){const t=this._model.timeScale(),i=Math.round(t.width()/t.barSpacing());return e+Math.max(3,Math.round(.15*i))}_changeEntryPoint(e){const t=this.properties().childs(),i=t.stopPrice.value(),r=t.targetPrice.value(),s=1/this.ownerSourceBase(),o=Math.min(i,r)+s,n=Math.max(i,r)-s;e.price=Math.max(o,Math.min(n,this._roundPrice(e.price))),this.setPoints([e,{...this._points[1],price:e.price}]),t.stopPrice.setValue(i),t.targetPrice.setValue(r)}_updateStudySource(){if(!this._metaInfo||this._isDestroyed)return;const e=this._properties.childs().currency.value(),t=this._model.mainSeries(),i="NONE"!==e&&e!==t.currency()&&!this.isSourceHidden();if(!i&&this._studySource?(this._studySource.destroy(),this._studySource=null,this._properties.childs().entryPointCurrencyRate.setValue(1),this._properties.childs().closePointCurrencyRate.setValue(1)):i&&!this._studySource&&(this._studySource=new RiskRewardStudyDataSource(this._model.chartApi(),t.seriesSource()),this._studySource.nonSeriesData().subscribe((e=>{e&&(this._properties.childs().entryPointCurrencyRate.setValue(e.currency_ratio[0]),this._properties.childs().closePointCurrencyRate.setValue(e.currency_ratio[1]??e.currency_ratio[0]))}))),this._studySource&&this._points.length>=2){const i=this._model.timeScale(),s=t.data().bars().firstIndex(),o=t.data().bars().lastIndex();if(null===s||null===o)return;const n=Math.min(o,Math.max(s,this._points[0].index)),a=Math.min(o,Math.max(s,this._points[1].index)),l=i.indexToTimePoint(n),c=i.indexToTimePoint(a);if(null!==l&&null!==c){const t={...this._studySource.inputs(),start_time:1e3*l,end_time:1e3*c,entry_price:this.entryPrice(),target_price:this.profitPrice(),stop_price:this.stopPrice(),account_currency:e};(0,
r.default)(t,this._studySource.inputs())||this._studySource.setInputs(t),this._studySource.isStarted()||this._studySource.start()}}}_updatePriceLevelsIfNeeded(){if(this._symbolSourceSymbolInfo.value()&&this._isActualSymbolParams()&&(this._actualOwnerSourceBase=this.ownerSourceBase(),this._restoredOwnerSourceBase)){const e=this._actualOwnerSourceBase/this._restoredOwnerSourceBase;this._restoredOwnerSourceBase=null;const{stopLevel:t,profitLevel:i}=this.properties().childs(),r=t.value(),s=i.value();t.setValue(r*e),i.setValue(s*e)}}}},44430:(e,t,i)=>{i.d(t,{RiskRewardCalculator:()=>a});var r=i(85842),s=i(34192),o=i(57651),n=i(22496);class a{constructor(e,t){this._riskInChange=!1,this._properties=e,this._context=t;const i=this._properties.childs();i.stopLevel.subscribe(this,this.recalculate),i.stopLevel.subscribe(null,(()=>{i.stopPrice.fireChanged()})),i.profitLevel.subscribe(this,this.recalculate),i.profitLevel.subscribe(null,(()=>{i.targetPrice.fireChanged()})),i.risk.subscribe(this,this.recalculateRiskSize),i.accountSize.subscribe(this,this.recalculateRiskSize),i.riskDisplayMode.subscribe(this,this.recalculateRisk),i.entryPrice.subscribe(this,this.recalculateRiskSize),i.stopPrice.subscribe(this,this.recalculateRiskSize),i.profitLevel.subscribe(this,this.recalculateRiskSize),i.profitLevel.subscribe(this,this._context.syncPriceLevels),i.stopLevel.subscribe(this,this.recalculateRiskSize),i.stopLevel.subscribe(this,this._context.syncPriceLevels),i.qty.subscribe(this,this.recalculateRiskSize),i.entryPrice.subscribe(this,this.recalculateQty),i.stopPrice.subscribe(this,this.recalculateQty),i.riskSize.subscribe(this,this.recalculateQty),i.leverage.subscribe(this,this.recalculateQty),i.entryPrice.subscribe(this,this.recalculateAmount),i.profitLevel.subscribe(this,this.recalculateAmount),i.stopLevel.subscribe(this,this.recalculateAmount),i.accountSize.subscribe(this,this.recalculateAmount),i.riskSize.subscribe(this,this.recalculateAmount),i.qty.subscribe(this,this.recalculateAmount),[i.entryPointCurrencyRate,i.closePointCurrencyRate].forEach((e=>{e.subscribe(this,(()=>{this.recalculateAmount(),this.recalculateRiskSize(),this.recalculateQty()}))}))}roundPrice(e){const t=this._context.ownerSourceBase();return Math.round(e*t)/t}recalculateRiskSize(){if(this._riskInChange)return;const e=this._properties.childs(),t=e.risk.value(),i=e.riskDisplayMode.value(),r=e.accountSize.value();i===n.RiskDisplayMode.Percentage?e.riskSize.setValue(t/100*r):t>r?(e.risk.setValue(r),e.riskSize.setValue(r)):e.riskSize.setValue(t)}recalculateRisk(){const e=this._properties.childs(),t=e.riskDisplayMode.value(),i=e.riskSize.value(),r=e.accountSize.value();let s=e.risk.value();s=t===n.RiskDisplayMode.Percentage?(0,o.roundValue)(i/r*100):(0,o.roundValue)(r/100*s),this._riskInChange=!0,e.risk.setValue(parseFloat(this._riskFormatter(t).format(s,{ignoreLocaleNumberFormat:!0}))),this._riskInChange=!1}recalculate(){const e=this._context.points();if(0===e.length)return
;const t=this._properties.childs(),i=t.targetPrice.value(),r=t.stopPrice.value(),s=this._context.pointsWithInterval(),o=[s[0],s[1]],n=this.calculateActualEntry(e[0],e[1]),a=this._context.interval();if(n){o.push({...n,interval:a});const t=this.findClosePoint(n,e[1]);t&&o.push({...t,interval:a})}this._context.assignPoints(o),i!==t.targetPrice.value()&&t.targetPrice.fireChanged(),r!==t.stopPrice.value()&&t.stopPrice.fireChanged()}recalculateAmount(){if(0===this._context.points().length)return;const e=this._properties.childs(),t=e.accountSize.value(),i=e.entryPrice.value(),r=e.qty.value(),s=e.stopPrice.value(),n=e.targetPrice.value(),a=this._context.ownerSourcePointValue();(0,o.setNumberPropertyValueNaNSafe)(e.amountTarget,this.amountTarget(t,n,i,r,a)),(0,o.setNumberPropertyValueNaNSafe)(e.amountStop,this.amountStop(t,s,i,r,a))}recalculateQty(){if(0===this._context.points().length)return;const e=this._properties.childs(),t=e.entryPrice.value(),i=e.stopPrice.value(),r=e.riskSize.value(),s=this._entryPointCurrencyRate(),n=e.leverage.value(),a=null===s?NaN:n*e.accountSize.value()/(t*this._context.ownerSourcePointValue()*s),l=null===s?NaN:r/(Math.abs(t-i)*this._context.ownerSourcePointValue()*s),c=Math.min(l,a);(0,o.setNumberPropertyValueNaNSafe)(e.qty,c)}calculateActualEntry(e,t){const i=this._context.bars();if(i.isEmpty())return null;const s=(0,r.ensureNotNull)(i.firstIndex()),o=Math.max(e.index,s),n=e.price,a=(0,r.ensureNotNull)(i.lastIndex()),l=Math.min(a,t.index-1);for(const e of i.rangeIterator(o,l+1)){const t=e.value;if(null!==t&&(0,r.ensure)(t[2])>=n&&(0,r.ensure)(t[3])<=n)return{index:e.index,price:n}}return null}entryPrice(){const e=this._context.points();return 0===e.length?this._context.timePoints()[0].price:e[0].price}findClosePoint(e,t){const i=this._context.bars(),s=(0,r.ensureNotNull)(i.firstIndex()),o=Math.max(e.index,s),n=(0,r.ensureNotNull)(i.lastIndex()),a=Math.min(n,t.index-1);for(const e of i.rangeIterator(o,a+1)){const t=e.value;if(null===t)continue;const i=this._checkStopPrice(t);if(null!=i)return{index:e.index,price:i}}return null}autoAdjustToPriceRange(e){if(e&&!e.isEmpty()){const t=Math.round(.2*e.length()*this._context.ownerSourceBase());this._properties.merge({stopLevel:t,profitLevel:t})}}_entryPointCurrencyRate(){return this._properties.childs().entryPointCurrencyRate.value()}_closePointCurrencyRate(){return this._properties.childs().closePointCurrencyRate.value()}_riskFormatter(e){return e===n.RiskDisplayMode.Percentage?(0,s.getNumericFormatter)(2):(0,s.getNumericFormatter)()}}},22496:(e,t,i)=>{var r;i.d(t,{RiskDisplayMode:()=>r}),function(e){e.Percentage="percents",e.Money="money"}(r||(r={}))},79920:(e,t,i)=>{i.r(t),i.d(t,{LineToolRiskRewardLong:()=>l});var r=i(57651),s=i(24427),o=i(85842),n=i(44430);class a extends n.RiskRewardCalculator{stopPrice(){return this.entryPrice()-this._properties.childs().stopLevel.value()/this._context.ownerSourceBase()}profitPrice(){return this.entryPrice()+this._properties.childs().profitLevel.value()/this._context.ownerSourceBase()}calculatePL(e){
return e-this.entryPrice()}prepareStopPrice(e){e=this.roundPrice(e);const t=this.entryPrice()-1/this._context.ownerSourceBase();return Math.min(e,t)}prepareProfitPrice(e){e=this.roundPrice(e);const t=this.entryPrice()+1/this._context.ownerSourceBase();return Math.max(e,t)}amountTarget(e,t,i,s,o){const n=this._closePointCurrencyRate();return null===n?NaN:(0,r.roundValue)(e+(t-i)*s*o/n)}amountStop(e,t,i,s,o){const n=this._closePointCurrencyRate();return null===n?NaN:(0,r.roundValue)(e-(i-t)*s*o/n)}calculatePLForTP(e,t,i,r){return(e-t)*i*r}calculatePLForSL(e,t,i,r){return(e-t)*i*r}_checkStopPrice(e){const t=this.stopPrice(),i=this.profitPrice();return(0,o.ensure)(e[3])<=t?this.stopPrice():(0,o.ensure)(e[2])>=i?this.profitPrice():null}}class l extends s.LineToolRiskRewardBase{constructor(e,t,i,r){super(a,e,t??l.createProperties(e.backgroundTheme().spawnOwnership()),i,r)}name(){return"Risk/Reward long"}static createProperties(e,t){const i=r.LineToolRiskRewardLongPropertiesImpl.create(e,t);return this._configureProperties(i),i}_orderSide(){throw new Error("not supported")}}(0,s.registerReversibleTool)("LineToolRiskRewardShort",{targetToolName:"LineToolRiskRewardLong",propertiesFactory:(e,t)=>l.createProperties(e,t)})},82384:(e,t,i)=>{i.r(t),i.d(t,{LineToolRiskRewardShort:()=>l});var r=i(57651),s=i(24427),o=i(85842),n=i(44430);class a extends n.RiskRewardCalculator{stopPrice(){return this.entryPrice()+this._properties.childs().stopLevel.value()/this._context.ownerSourceBase()}profitPrice(){return this.entryPrice()-this._properties.childs().profitLevel.value()/this._context.ownerSourceBase()}calculatePL(e){return this.entryPrice()-e}prepareStopPrice(e){e=this.roundPrice(e);const t=this.entryPrice()+1/this._context.ownerSourceBase();return Math.max(e,t)}prepareProfitPrice(e){e=this.roundPrice(e);const t=this.entryPrice()-1/this._context.ownerSourceBase();return Math.min(e,t)}amountTarget(e,t,i,s,o){const n=this._closePointCurrencyRate();return null===n?NaN:(0,r.roundValue)(e+(i-t)*s*o/n)}amountStop(e,t,i,s,o){const n=this._closePointCurrencyRate();return null===n?NaN:(0,r.roundValue)(e-(t-i)*s*o/n)}calculatePLForTP(e,t,i,r){return(t-e)*i*r}calculatePLForSL(e,t,i,r){return(t-e)*i*r}_checkStopPrice(e){const t=this.stopPrice(),i=this.profitPrice();return(0,o.ensure)(e[2])>=t?this.stopPrice():(0,o.ensure)(e[3])<=i?this.profitPrice():null}}class l extends s.LineToolRiskRewardBase{constructor(e,t,i,r){super(a,e,t??l.createProperties(e.backgroundTheme().spawnOwnership()),i,r)}name(){return"Risk/Reward short"}static createProperties(e,t){const i=r.LineToolRiskRewardShortPropertiesImpl.create(e,t);return this._configureProperties(i),i}_orderSide(){throw new Error("not supported")}}(0,s.registerReversibleTool)("LineToolRiskRewardLong",{targetToolName:"LineToolRiskRewardShort",propertiesFactory:(e,t)=>l.createProperties(e,t)})},8165:(e,t,i)=>{i.d(t,{LineAnchorRenderer:()=>g,lineSourcePaneViewPointToLineAnchorPoint:()=>S,lineSourcePaneViewPointToLineAnchorPoint2:()=>v,mapLineSourcePaneViewPointToLineAnchorPoint:()=>y})
;var r=i(57415),s=i(91069),o=i(85842),n=i(51946),a=i(7321),l=i(83077),c=i(28031),u=i(72244),h=i(57507);function d(e,t,i,r){const{point:s}=t,o=i+r/2;(0,n.drawRoundRect)(e,s.x-o,s.y-o,2*o,2*o,(i+r)/2),e.closePath(),e.lineWidth=r}function p(e,t,i,r){e.globalAlpha=.2,d(e,t,i,r),e.stroke(),e.globalAlpha=1}function _(e,t,i,r){d(e,t,i-r,r),e.fill(),e.stroke()}function P(e,t,i,r){const{point:s}=t;e.globalAlpha=.2,e.beginPath(),e.arc(s.x,s.y,i+r/2,0,2*Math.PI,!0),e.closePath(),e.lineWidth=r,e.stroke(),e.globalAlpha=1}function f(e,t,i,r){const{point:s}=t;e.beginPath(),e.arc(s.x,s.y,i-r/2,0,2*Math.PI,!0),e.closePath(),e.lineWidth=r,e.fill(),e.stroke()}class g extends h.BitmapCoordinatesPaneRenderer{constructor(e){super(),this._data=e??null}setData(e){this._data=e}hitTest(e){if(null===this._data||this._data.disableInteractions)return null;const{radius:t,points:i}=this._data,r=t+(0,u.interactionTolerance)().anchor;for(const t of i){if(t.point.subtract(e).length()<=r)return new l.HitTestResult(t.hitTarget??l.HitTarget.ChangePoint,{areaName:l.AreaName.AnchorPoint,pointIndex:t.pointIndex,cursorType:t.cursorType??c.PaneCursorType.Default,activeItem:t.activeItem,snappingPrice:t.snappingPrice,snappingIndex:t.snappingIndex,nonDiscreteIndex:t.nonDiscreteIndex,possibleMovingDirections:t.possibleMovingDirections,clickHandler:this._data.clickHandler,tapHandler:this._data.clickHandler,ownerSourceId:this._data.ownerSourceId})}return null}doesIntersectWithBox(e){return null!==this._data&&this._data.points.some((t=>(0,s.pointInBox)(t.point,e)))}_drawImpl(e){if(null===this._data||!this._data.visible)return;const t=[],i=[],r=[],s=[];for(let e=0;e{i.d(t,{factoryDefaultsForCurrentTheme:()=>l});var r=i(35558),s=i(57600),o=i(85842),n=i(49841),a=i(47097);function l(e,t){const i=n.watchedTheme.value()??a.StdTheme.Light,l=(0,s.default)(e);return(0,r.default)(l,(0,o.ensureDefined)(t.get(i))),l}}}]);