hyperprop-charting-library 0.1.82 → 0.1.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2503,11 +2503,12 @@ function createChart(element, options = {}) {
2503
2503
  handleAt(leftX, stopY, drawing.color);
2504
2504
  handleAt(rightX, entryY, drawing.color);
2505
2505
  const tick = getConfiguredTickSize();
2506
- const pctOf = (price) => {
2506
+ const pctOfDist = (dist) => {
2507
2507
  if (!Number.isFinite(entry.price) || entry.price === 0) return "0.00%";
2508
- return `${((price - entry.price) / Math.abs(entry.price) * 100).toFixed(2)}%`;
2508
+ const pct = dist / Math.abs(entry.price) * 100;
2509
+ return `${pct < 1 ? pct.toFixed(3) : pct.toFixed(2)}%`;
2509
2510
  };
2510
- const ticksOf = (price) => tick > 0 ? ` ${Math.round(Math.abs(price - entry.price) / tick)}t` : "";
2511
+ const ticksOfDist = (dist) => tick > 0 ? ` ${Math.round(dist / tick)}` : "";
2511
2512
  const targetDist = Math.abs(target.price - entry.price);
2512
2513
  const stopDist = Math.abs(entry.price - stop.price);
2513
2514
  const rr = stopDist > 0 ? targetDist / stopDist : 0;
@@ -2517,16 +2518,18 @@ function createChart(element, options = {}) {
2517
2518
  const qtyRaw = riskAmount > 0 && stopDist > 0 ? riskAmount / (stopDist * effectivePointValue) : 0;
2518
2519
  const hasMoney = qtyRaw > 0 && Number.isFinite(qtyRaw);
2519
2520
  const qtyText = hasMoney ? qtyRaw.toFixed(Math.max(0, drawing.qtyPrecision)) : "";
2520
- const formatAmount = (value) => Math.abs(value) >= 1e3 ? value.toFixed(0) : value.toFixed(2);
2521
- const targetAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * targetDist * effectivePointValue)}` : "";
2522
- const stopAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * stopDist * effectivePointValue)}` : "";
2521
+ const formatAmount = (value) => value.toFixed(2);
2522
+ const targetAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * target.price * effectivePointValue)}` : "";
2523
+ const stopAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * stop.price * effectivePointValue)}` : "";
2523
2524
  const drawPositionPill = (text, centerX, centerY, bg) => {
2525
+ const lines = Array.isArray(text) ? text : [text];
2524
2526
  const prevFont = ctx.font;
2525
2527
  ctx.font = `500 11px ${mergedOptions.fontFamily}`;
2526
2528
  const padding = 6;
2527
- const textW = ctx.measureText(text).width;
2529
+ const lineH = 14;
2530
+ const textW = Math.max(...lines.map((line) => ctx.measureText(line).width));
2528
2531
  const pillW = textW + padding * 2;
2529
- const pillH = 18;
2532
+ const pillH = lines.length === 1 ? 18 : lines.length * lineH + 6;
2530
2533
  const pillX = centerX - pillW / 2;
2531
2534
  const pillY = centerY - pillH / 2;
2532
2535
  ctx.fillStyle = bg;
@@ -2534,23 +2537,25 @@ function createChart(element, options = {}) {
2534
2537
  ctx.fillStyle = labelTextColor;
2535
2538
  ctx.textAlign = "center";
2536
2539
  ctx.textBaseline = "middle";
2537
- ctx.fillText(text, centerX, pillY + pillH / 2);
2540
+ const startY = pillY + pillH / 2 - (lines.length - 1) * lineH / 2;
2541
+ lines.forEach((line, lineIndex) => ctx.fillText(line, centerX, startY + lineIndex * lineH));
2538
2542
  ctx.font = prevFont;
2539
2543
  };
2540
- drawPositionPill(`Target ${formatPrice(target.price)} (${pctOf(target.price)})${ticksOf(target.price)}${targetAmountText}`, cx, targetY, profitLine);
2541
- drawPositionPill(`Stop ${formatPrice(stop.price)} (${pctOf(stop.price)})${ticksOf(stop.price)}${stopAmountText}`, cx, stopY, lossLine);
2542
- let centerText;
2544
+ drawPositionPill(`Target: ${formatPrice(targetDist)} (${pctOfDist(targetDist)})${ticksOfDist(targetDist)}${targetAmountText}`, cx, targetY, profitLine);
2545
+ drawPositionPill(`Stop: ${formatPrice(stopDist)} (${pctOfDist(stopDist)})${ticksOfDist(stopDist)}${stopAmountText}`, cx, stopY, lossLine);
2546
+ let centerLines;
2543
2547
  let centerBg;
2544
2548
  if (positionHit) {
2545
- const pnl = positionHit.profit ? qtyRaw * targetDist * effectivePointValue : -(qtyRaw * stopDist * effectivePointValue);
2546
- const pnlText = hasMoney ? `Closed P&L: ${formatAmount(pnl)}` : `Closed ${positionHit.profit ? "+" : "\u2212"}${formatPrice(Math.abs(positionHit.price - entry.price))}`;
2547
- centerText = hasMoney ? `${pnlText}, Qty: ${qtyText} RR ${rr.toFixed(2)}` : `${pnlText} RR ${rr.toFixed(2)}`;
2549
+ const pnlPoints = positionHit.profit ? targetDist : -stopDist;
2550
+ const line1 = hasMoney ? `Closed P&L: ${formatPrice(pnlPoints)}, Qty: ${qtyText}` : `Closed P&L: ${formatPrice(pnlPoints)}`;
2551
+ centerLines = [line1, `Risk/reward ratio: ${rr.toFixed(2)}`];
2548
2552
  centerBg = positionHit.profit ? profitLine : lossLine;
2549
2553
  } else {
2550
- centerText = hasMoney ? `Entry ${formatPrice(entry.price)} Qty ${qtyText} RR ${rr.toFixed(2)}` : `Entry ${formatPrice(entry.price)} RR ${rr.toFixed(2)}`;
2554
+ const line1 = hasMoney ? `Entry: ${formatPrice(entry.price)}, Qty: ${qtyText}` : `Entry: ${formatPrice(entry.price)}`;
2555
+ centerLines = [line1, `Risk/reward ratio: ${rr.toFixed(2)}`];
2551
2556
  centerBg = hexToRgba(drawing.color, 0.92);
2552
2557
  }
2553
- drawPositionPill(centerText, cx, entryY, centerBg);
2558
+ drawPositionPill(centerLines, cx, entryY, centerBg);
2554
2559
  if (drawing.label) {
2555
2560
  drawDrawingLabel(drawing.label, cx, Math.min(targetY, stopY) - 4, drawing.color);
2556
2561
  }
@@ -2477,11 +2477,12 @@ function createChart(element, options = {}) {
2477
2477
  handleAt(leftX, stopY, drawing.color);
2478
2478
  handleAt(rightX, entryY, drawing.color);
2479
2479
  const tick = getConfiguredTickSize();
2480
- const pctOf = (price) => {
2480
+ const pctOfDist = (dist) => {
2481
2481
  if (!Number.isFinite(entry.price) || entry.price === 0) return "0.00%";
2482
- return `${((price - entry.price) / Math.abs(entry.price) * 100).toFixed(2)}%`;
2482
+ const pct = dist / Math.abs(entry.price) * 100;
2483
+ return `${pct < 1 ? pct.toFixed(3) : pct.toFixed(2)}%`;
2483
2484
  };
2484
- const ticksOf = (price) => tick > 0 ? ` ${Math.round(Math.abs(price - entry.price) / tick)}t` : "";
2485
+ const ticksOfDist = (dist) => tick > 0 ? ` ${Math.round(dist / tick)}` : "";
2485
2486
  const targetDist = Math.abs(target.price - entry.price);
2486
2487
  const stopDist = Math.abs(entry.price - stop.price);
2487
2488
  const rr = stopDist > 0 ? targetDist / stopDist : 0;
@@ -2491,16 +2492,18 @@ function createChart(element, options = {}) {
2491
2492
  const qtyRaw = riskAmount > 0 && stopDist > 0 ? riskAmount / (stopDist * effectivePointValue) : 0;
2492
2493
  const hasMoney = qtyRaw > 0 && Number.isFinite(qtyRaw);
2493
2494
  const qtyText = hasMoney ? qtyRaw.toFixed(Math.max(0, drawing.qtyPrecision)) : "";
2494
- const formatAmount = (value) => Math.abs(value) >= 1e3 ? value.toFixed(0) : value.toFixed(2);
2495
- const targetAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * targetDist * effectivePointValue)}` : "";
2496
- const stopAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * stopDist * effectivePointValue)}` : "";
2495
+ const formatAmount = (value) => value.toFixed(2);
2496
+ const targetAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * target.price * effectivePointValue)}` : "";
2497
+ const stopAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * stop.price * effectivePointValue)}` : "";
2497
2498
  const drawPositionPill = (text, centerX, centerY, bg) => {
2499
+ const lines = Array.isArray(text) ? text : [text];
2498
2500
  const prevFont = ctx.font;
2499
2501
  ctx.font = `500 11px ${mergedOptions.fontFamily}`;
2500
2502
  const padding = 6;
2501
- const textW = ctx.measureText(text).width;
2503
+ const lineH = 14;
2504
+ const textW = Math.max(...lines.map((line) => ctx.measureText(line).width));
2502
2505
  const pillW = textW + padding * 2;
2503
- const pillH = 18;
2506
+ const pillH = lines.length === 1 ? 18 : lines.length * lineH + 6;
2504
2507
  const pillX = centerX - pillW / 2;
2505
2508
  const pillY = centerY - pillH / 2;
2506
2509
  ctx.fillStyle = bg;
@@ -2508,23 +2511,25 @@ function createChart(element, options = {}) {
2508
2511
  ctx.fillStyle = labelTextColor;
2509
2512
  ctx.textAlign = "center";
2510
2513
  ctx.textBaseline = "middle";
2511
- ctx.fillText(text, centerX, pillY + pillH / 2);
2514
+ const startY = pillY + pillH / 2 - (lines.length - 1) * lineH / 2;
2515
+ lines.forEach((line, lineIndex) => ctx.fillText(line, centerX, startY + lineIndex * lineH));
2512
2516
  ctx.font = prevFont;
2513
2517
  };
2514
- drawPositionPill(`Target ${formatPrice(target.price)} (${pctOf(target.price)})${ticksOf(target.price)}${targetAmountText}`, cx, targetY, profitLine);
2515
- drawPositionPill(`Stop ${formatPrice(stop.price)} (${pctOf(stop.price)})${ticksOf(stop.price)}${stopAmountText}`, cx, stopY, lossLine);
2516
- let centerText;
2518
+ drawPositionPill(`Target: ${formatPrice(targetDist)} (${pctOfDist(targetDist)})${ticksOfDist(targetDist)}${targetAmountText}`, cx, targetY, profitLine);
2519
+ drawPositionPill(`Stop: ${formatPrice(stopDist)} (${pctOfDist(stopDist)})${ticksOfDist(stopDist)}${stopAmountText}`, cx, stopY, lossLine);
2520
+ let centerLines;
2517
2521
  let centerBg;
2518
2522
  if (positionHit) {
2519
- const pnl = positionHit.profit ? qtyRaw * targetDist * effectivePointValue : -(qtyRaw * stopDist * effectivePointValue);
2520
- const pnlText = hasMoney ? `Closed P&L: ${formatAmount(pnl)}` : `Closed ${positionHit.profit ? "+" : "\u2212"}${formatPrice(Math.abs(positionHit.price - entry.price))}`;
2521
- centerText = hasMoney ? `${pnlText}, Qty: ${qtyText} RR ${rr.toFixed(2)}` : `${pnlText} RR ${rr.toFixed(2)}`;
2523
+ const pnlPoints = positionHit.profit ? targetDist : -stopDist;
2524
+ const line1 = hasMoney ? `Closed P&L: ${formatPrice(pnlPoints)}, Qty: ${qtyText}` : `Closed P&L: ${formatPrice(pnlPoints)}`;
2525
+ centerLines = [line1, `Risk/reward ratio: ${rr.toFixed(2)}`];
2522
2526
  centerBg = positionHit.profit ? profitLine : lossLine;
2523
2527
  } else {
2524
- centerText = hasMoney ? `Entry ${formatPrice(entry.price)} Qty ${qtyText} RR ${rr.toFixed(2)}` : `Entry ${formatPrice(entry.price)} RR ${rr.toFixed(2)}`;
2528
+ const line1 = hasMoney ? `Entry: ${formatPrice(entry.price)}, Qty: ${qtyText}` : `Entry: ${formatPrice(entry.price)}`;
2529
+ centerLines = [line1, `Risk/reward ratio: ${rr.toFixed(2)}`];
2525
2530
  centerBg = hexToRgba(drawing.color, 0.92);
2526
2531
  }
2527
- drawPositionPill(centerText, cx, entryY, centerBg);
2532
+ drawPositionPill(centerLines, cx, entryY, centerBg);
2528
2533
  if (drawing.label) {
2529
2534
  drawDrawingLabel(drawing.label, cx, Math.min(targetY, stopY) - 4, drawing.color);
2530
2535
  }
package/dist/index.cjs CHANGED
@@ -2503,11 +2503,12 @@ function createChart(element, options = {}) {
2503
2503
  handleAt(leftX, stopY, drawing.color);
2504
2504
  handleAt(rightX, entryY, drawing.color);
2505
2505
  const tick = getConfiguredTickSize();
2506
- const pctOf = (price) => {
2506
+ const pctOfDist = (dist) => {
2507
2507
  if (!Number.isFinite(entry.price) || entry.price === 0) return "0.00%";
2508
- return `${((price - entry.price) / Math.abs(entry.price) * 100).toFixed(2)}%`;
2508
+ const pct = dist / Math.abs(entry.price) * 100;
2509
+ return `${pct < 1 ? pct.toFixed(3) : pct.toFixed(2)}%`;
2509
2510
  };
2510
- const ticksOf = (price) => tick > 0 ? ` ${Math.round(Math.abs(price - entry.price) / tick)}t` : "";
2511
+ const ticksOfDist = (dist) => tick > 0 ? ` ${Math.round(dist / tick)}` : "";
2511
2512
  const targetDist = Math.abs(target.price - entry.price);
2512
2513
  const stopDist = Math.abs(entry.price - stop.price);
2513
2514
  const rr = stopDist > 0 ? targetDist / stopDist : 0;
@@ -2517,16 +2518,18 @@ function createChart(element, options = {}) {
2517
2518
  const qtyRaw = riskAmount > 0 && stopDist > 0 ? riskAmount / (stopDist * effectivePointValue) : 0;
2518
2519
  const hasMoney = qtyRaw > 0 && Number.isFinite(qtyRaw);
2519
2520
  const qtyText = hasMoney ? qtyRaw.toFixed(Math.max(0, drawing.qtyPrecision)) : "";
2520
- const formatAmount = (value) => Math.abs(value) >= 1e3 ? value.toFixed(0) : value.toFixed(2);
2521
- const targetAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * targetDist * effectivePointValue)}` : "";
2522
- const stopAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * stopDist * effectivePointValue)}` : "";
2521
+ const formatAmount = (value) => value.toFixed(2);
2522
+ const targetAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * target.price * effectivePointValue)}` : "";
2523
+ const stopAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * stop.price * effectivePointValue)}` : "";
2523
2524
  const drawPositionPill = (text, centerX, centerY, bg) => {
2525
+ const lines = Array.isArray(text) ? text : [text];
2524
2526
  const prevFont = ctx.font;
2525
2527
  ctx.font = `500 11px ${mergedOptions.fontFamily}`;
2526
2528
  const padding = 6;
2527
- const textW = ctx.measureText(text).width;
2529
+ const lineH = 14;
2530
+ const textW = Math.max(...lines.map((line) => ctx.measureText(line).width));
2528
2531
  const pillW = textW + padding * 2;
2529
- const pillH = 18;
2532
+ const pillH = lines.length === 1 ? 18 : lines.length * lineH + 6;
2530
2533
  const pillX = centerX - pillW / 2;
2531
2534
  const pillY = centerY - pillH / 2;
2532
2535
  ctx.fillStyle = bg;
@@ -2534,23 +2537,25 @@ function createChart(element, options = {}) {
2534
2537
  ctx.fillStyle = labelTextColor;
2535
2538
  ctx.textAlign = "center";
2536
2539
  ctx.textBaseline = "middle";
2537
- ctx.fillText(text, centerX, pillY + pillH / 2);
2540
+ const startY = pillY + pillH / 2 - (lines.length - 1) * lineH / 2;
2541
+ lines.forEach((line, lineIndex) => ctx.fillText(line, centerX, startY + lineIndex * lineH));
2538
2542
  ctx.font = prevFont;
2539
2543
  };
2540
- drawPositionPill(`Target ${formatPrice(target.price)} (${pctOf(target.price)})${ticksOf(target.price)}${targetAmountText}`, cx, targetY, profitLine);
2541
- drawPositionPill(`Stop ${formatPrice(stop.price)} (${pctOf(stop.price)})${ticksOf(stop.price)}${stopAmountText}`, cx, stopY, lossLine);
2542
- let centerText;
2544
+ drawPositionPill(`Target: ${formatPrice(targetDist)} (${pctOfDist(targetDist)})${ticksOfDist(targetDist)}${targetAmountText}`, cx, targetY, profitLine);
2545
+ drawPositionPill(`Stop: ${formatPrice(stopDist)} (${pctOfDist(stopDist)})${ticksOfDist(stopDist)}${stopAmountText}`, cx, stopY, lossLine);
2546
+ let centerLines;
2543
2547
  let centerBg;
2544
2548
  if (positionHit) {
2545
- const pnl = positionHit.profit ? qtyRaw * targetDist * effectivePointValue : -(qtyRaw * stopDist * effectivePointValue);
2546
- const pnlText = hasMoney ? `Closed P&L: ${formatAmount(pnl)}` : `Closed ${positionHit.profit ? "+" : "\u2212"}${formatPrice(Math.abs(positionHit.price - entry.price))}`;
2547
- centerText = hasMoney ? `${pnlText}, Qty: ${qtyText} RR ${rr.toFixed(2)}` : `${pnlText} RR ${rr.toFixed(2)}`;
2549
+ const pnlPoints = positionHit.profit ? targetDist : -stopDist;
2550
+ const line1 = hasMoney ? `Closed P&L: ${formatPrice(pnlPoints)}, Qty: ${qtyText}` : `Closed P&L: ${formatPrice(pnlPoints)}`;
2551
+ centerLines = [line1, `Risk/reward ratio: ${rr.toFixed(2)}`];
2548
2552
  centerBg = positionHit.profit ? profitLine : lossLine;
2549
2553
  } else {
2550
- centerText = hasMoney ? `Entry ${formatPrice(entry.price)} Qty ${qtyText} RR ${rr.toFixed(2)}` : `Entry ${formatPrice(entry.price)} RR ${rr.toFixed(2)}`;
2554
+ const line1 = hasMoney ? `Entry: ${formatPrice(entry.price)}, Qty: ${qtyText}` : `Entry: ${formatPrice(entry.price)}`;
2555
+ centerLines = [line1, `Risk/reward ratio: ${rr.toFixed(2)}`];
2551
2556
  centerBg = hexToRgba(drawing.color, 0.92);
2552
2557
  }
2553
- drawPositionPill(centerText, cx, entryY, centerBg);
2558
+ drawPositionPill(centerLines, cx, entryY, centerBg);
2554
2559
  if (drawing.label) {
2555
2560
  drawDrawingLabel(drawing.label, cx, Math.min(targetY, stopY) - 4, drawing.color);
2556
2561
  }
package/dist/index.js CHANGED
@@ -2477,11 +2477,12 @@ function createChart(element, options = {}) {
2477
2477
  handleAt(leftX, stopY, drawing.color);
2478
2478
  handleAt(rightX, entryY, drawing.color);
2479
2479
  const tick = getConfiguredTickSize();
2480
- const pctOf = (price) => {
2480
+ const pctOfDist = (dist) => {
2481
2481
  if (!Number.isFinite(entry.price) || entry.price === 0) return "0.00%";
2482
- return `${((price - entry.price) / Math.abs(entry.price) * 100).toFixed(2)}%`;
2482
+ const pct = dist / Math.abs(entry.price) * 100;
2483
+ return `${pct < 1 ? pct.toFixed(3) : pct.toFixed(2)}%`;
2483
2484
  };
2484
- const ticksOf = (price) => tick > 0 ? ` ${Math.round(Math.abs(price - entry.price) / tick)}t` : "";
2485
+ const ticksOfDist = (dist) => tick > 0 ? ` ${Math.round(dist / tick)}` : "";
2485
2486
  const targetDist = Math.abs(target.price - entry.price);
2486
2487
  const stopDist = Math.abs(entry.price - stop.price);
2487
2488
  const rr = stopDist > 0 ? targetDist / stopDist : 0;
@@ -2491,16 +2492,18 @@ function createChart(element, options = {}) {
2491
2492
  const qtyRaw = riskAmount > 0 && stopDist > 0 ? riskAmount / (stopDist * effectivePointValue) : 0;
2492
2493
  const hasMoney = qtyRaw > 0 && Number.isFinite(qtyRaw);
2493
2494
  const qtyText = hasMoney ? qtyRaw.toFixed(Math.max(0, drawing.qtyPrecision)) : "";
2494
- const formatAmount = (value) => Math.abs(value) >= 1e3 ? value.toFixed(0) : value.toFixed(2);
2495
- const targetAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * targetDist * effectivePointValue)}` : "";
2496
- const stopAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * stopDist * effectivePointValue)}` : "";
2495
+ const formatAmount = (value) => value.toFixed(2);
2496
+ const targetAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * target.price * effectivePointValue)}` : "";
2497
+ const stopAmountText = hasMoney ? `, Amount: ${formatAmount(qtyRaw * stop.price * effectivePointValue)}` : "";
2497
2498
  const drawPositionPill = (text, centerX, centerY, bg) => {
2499
+ const lines = Array.isArray(text) ? text : [text];
2498
2500
  const prevFont = ctx.font;
2499
2501
  ctx.font = `500 11px ${mergedOptions.fontFamily}`;
2500
2502
  const padding = 6;
2501
- const textW = ctx.measureText(text).width;
2503
+ const lineH = 14;
2504
+ const textW = Math.max(...lines.map((line) => ctx.measureText(line).width));
2502
2505
  const pillW = textW + padding * 2;
2503
- const pillH = 18;
2506
+ const pillH = lines.length === 1 ? 18 : lines.length * lineH + 6;
2504
2507
  const pillX = centerX - pillW / 2;
2505
2508
  const pillY = centerY - pillH / 2;
2506
2509
  ctx.fillStyle = bg;
@@ -2508,23 +2511,25 @@ function createChart(element, options = {}) {
2508
2511
  ctx.fillStyle = labelTextColor;
2509
2512
  ctx.textAlign = "center";
2510
2513
  ctx.textBaseline = "middle";
2511
- ctx.fillText(text, centerX, pillY + pillH / 2);
2514
+ const startY = pillY + pillH / 2 - (lines.length - 1) * lineH / 2;
2515
+ lines.forEach((line, lineIndex) => ctx.fillText(line, centerX, startY + lineIndex * lineH));
2512
2516
  ctx.font = prevFont;
2513
2517
  };
2514
- drawPositionPill(`Target ${formatPrice(target.price)} (${pctOf(target.price)})${ticksOf(target.price)}${targetAmountText}`, cx, targetY, profitLine);
2515
- drawPositionPill(`Stop ${formatPrice(stop.price)} (${pctOf(stop.price)})${ticksOf(stop.price)}${stopAmountText}`, cx, stopY, lossLine);
2516
- let centerText;
2518
+ drawPositionPill(`Target: ${formatPrice(targetDist)} (${pctOfDist(targetDist)})${ticksOfDist(targetDist)}${targetAmountText}`, cx, targetY, profitLine);
2519
+ drawPositionPill(`Stop: ${formatPrice(stopDist)} (${pctOfDist(stopDist)})${ticksOfDist(stopDist)}${stopAmountText}`, cx, stopY, lossLine);
2520
+ let centerLines;
2517
2521
  let centerBg;
2518
2522
  if (positionHit) {
2519
- const pnl = positionHit.profit ? qtyRaw * targetDist * effectivePointValue : -(qtyRaw * stopDist * effectivePointValue);
2520
- const pnlText = hasMoney ? `Closed P&L: ${formatAmount(pnl)}` : `Closed ${positionHit.profit ? "+" : "\u2212"}${formatPrice(Math.abs(positionHit.price - entry.price))}`;
2521
- centerText = hasMoney ? `${pnlText}, Qty: ${qtyText} RR ${rr.toFixed(2)}` : `${pnlText} RR ${rr.toFixed(2)}`;
2523
+ const pnlPoints = positionHit.profit ? targetDist : -stopDist;
2524
+ const line1 = hasMoney ? `Closed P&L: ${formatPrice(pnlPoints)}, Qty: ${qtyText}` : `Closed P&L: ${formatPrice(pnlPoints)}`;
2525
+ centerLines = [line1, `Risk/reward ratio: ${rr.toFixed(2)}`];
2522
2526
  centerBg = positionHit.profit ? profitLine : lossLine;
2523
2527
  } else {
2524
- centerText = hasMoney ? `Entry ${formatPrice(entry.price)} Qty ${qtyText} RR ${rr.toFixed(2)}` : `Entry ${formatPrice(entry.price)} RR ${rr.toFixed(2)}`;
2528
+ const line1 = hasMoney ? `Entry: ${formatPrice(entry.price)}, Qty: ${qtyText}` : `Entry: ${formatPrice(entry.price)}`;
2529
+ centerLines = [line1, `Risk/reward ratio: ${rr.toFixed(2)}`];
2525
2530
  centerBg = hexToRgba(drawing.color, 0.92);
2526
2531
  }
2527
- drawPositionPill(centerText, cx, entryY, centerBg);
2532
+ drawPositionPill(centerLines, cx, entryY, centerBg);
2528
2533
  if (drawing.label) {
2529
2534
  drawDrawingLabel(drawing.label, cx, Math.min(targetY, stopY) - 4, drawing.color);
2530
2535
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperprop-charting-library",
3
- "version": "0.1.82",
3
+ "version": "0.1.83",
4
4
  "description": "Lightweight TypeScript charting core",
5
5
  "type": "module",
6
6
  "main": "./dist/hyperprop-charting-library.cjs",