acttrader-charts 1.3.0-beta.22 → 1.3.0-beta.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1171,9 +1171,11 @@ Sub-pane heights are user-resizable by dragging the separator between panes.
1171
1171
 
1172
1172
  ### SL/TP bracket labels — price or amount
1173
1173
 
1174
- By default an SL/TP pill reads `SL 4159.00`. With `bracketLabelMode: 'amount'`
1175
- it reads `SL -$290.80` — the money the position gains or loses if that bracket
1176
- is hit, currency symbol in front.
1174
+ By default an SL/TP pill reads `SL @4159.00` — the currency sign is never shown on
1175
+ a price. With `bracketLabelMode: 'amount'` it reads `SL -$290.80` — the money the
1176
+ position gains or loses if that bracket is hit, currency symbol in front and a
1177
+ minus only on a loss. `'priceAndAmount'` shows `SL @4159.00` at rest and
1178
+ `SL @4159.00 -$290.80` while the bracket is dragged.
1177
1179
 
1178
1180
  The chart has no access to contract specs or the account currency, so each level
1179
1181
  supplies what the maths needs:
@@ -1188,7 +1190,7 @@ chart.setLevels([{
1188
1190
  valuePerPoint: 1, // account-currency value of one price unit
1189
1191
  currencySymbol: '$', // optional per-level override
1190
1192
  }], 'label', 'price', 'position');
1191
- // pills render: SL -$290.80 TP +$189.20
1193
+ // pills render: SL -$290.80 TP $189.20
1192
1194
  ```
1193
1195
 
1194
1196
  ```
@@ -1177,14 +1177,15 @@ interface ChartConfig {
1177
1177
  /**
1178
1178
  * What the SL/TP bracket pills show.
1179
1179
  *
1180
- * `'price'` (default) renders the bracket price — `SL 4159.00`.
1180
+ * `'price'` (default) renders the bracket price — `SL @4159.00`. The currency
1181
+ * sign is never shown on a price, only on money values.
1181
1182
  * `'amount'` renders the money the position gains or loses if that bracket
1182
- * is hit — `SL -$290.80` — computed from the level's `lots`, `contractSize`
1183
- * and `valuePerPoint`. Falls back to the price for any level lacking the
1184
- * data needed to compute it, so a partial rollout degrades gracefully.
1185
- * `'priceAndAmount'` keeps the price but puts the currency symbol in front
1186
- * of it — `SL $1.27859` — and appends the P/L while the bracket is being
1187
- * dragged: `SL $1.27859 -$29.08`.
1183
+ * is hit — `SL -$290.80` (a minus only on a loss, no plus on a gain) —
1184
+ * computed from the level's `lots`, `contractSize` and `valuePerPoint`.
1185
+ * Falls back to the price for any level lacking the data needed to compute
1186
+ * it, so a partial rollout degrades gracefully.
1187
+ * `'priceAndAmount'` shows the price at rest — `SL @1.27859` — and appends
1188
+ * the P/L while the bracket is being dragged: `SL @1.27859 -$29.08`.
1188
1189
  */
1189
1190
  bracketLabelMode?: 'price' | 'amount' | 'priceAndAmount';
1190
1191
  /**
@@ -1177,14 +1177,15 @@ interface ChartConfig {
1177
1177
  /**
1178
1178
  * What the SL/TP bracket pills show.
1179
1179
  *
1180
- * `'price'` (default) renders the bracket price — `SL 4159.00`.
1180
+ * `'price'` (default) renders the bracket price — `SL @4159.00`. The currency
1181
+ * sign is never shown on a price, only on money values.
1181
1182
  * `'amount'` renders the money the position gains or loses if that bracket
1182
- * is hit — `SL -$290.80` — computed from the level's `lots`, `contractSize`
1183
- * and `valuePerPoint`. Falls back to the price for any level lacking the
1184
- * data needed to compute it, so a partial rollout degrades gracefully.
1185
- * `'priceAndAmount'` keeps the price but puts the currency symbol in front
1186
- * of it — `SL $1.27859` — and appends the P/L while the bracket is being
1187
- * dragged: `SL $1.27859 -$29.08`.
1183
+ * is hit — `SL -$290.80` (a minus only on a loss, no plus on a gain) —
1184
+ * computed from the level's `lots`, `contractSize` and `valuePerPoint`.
1185
+ * Falls back to the price for any level lacking the data needed to compute
1186
+ * it, so a partial rollout degrades gracefully.
1187
+ * `'priceAndAmount'` shows the price at rest — `SL @1.27859` — and appends
1188
+ * the P/L while the bracket is being dragged: `SL @1.27859 -$29.08`.
1188
1189
  */
1189
1190
  bracketLabelMode?: 'price' | 'amount' | 'priceAndAmount';
1190
1191
  /**
package/dist/index.cjs CHANGED
@@ -1935,8 +1935,7 @@ function bracketPnl(input) {
1935
1935
  function formatMoney(amount, symbol = "$", decimals = 2) {
1936
1936
  const rounded = Number(amount.toFixed(decimals));
1937
1937
  const magnitude = Math.abs(rounded).toFixed(decimals);
1938
- if (rounded === 0) return `${symbol}${magnitude}`;
1939
- return `${rounded > 0 ? "+" : "-"}${symbol}${magnitude}`;
1938
+ return `${rounded < 0 ? "-" : ""}${symbol}${magnitude}`;
1940
1939
  }
1941
1940
  function positionQty(input) {
1942
1941
  const { entryPrice, stopPrice, accountSize, riskPercent } = input;
@@ -2080,13 +2079,12 @@ function bracketBoxLabel(bracketType, price, precision, level, opts = DEFAULT_BR
2080
2079
  const pnl = amount();
2081
2080
  if (pnl !== null) return `${typeLabel} ${formatMoney(pnl, symbol)}`;
2082
2081
  }
2083
- if (opts.mode === "priceAndAmount") {
2084
- const priced = `${typeLabel} ${symbol}${price.toFixed(precision)}`;
2085
- if (!active) return priced;
2082
+ const priced = `${typeLabel} @${price.toFixed(precision)}`;
2083
+ if (opts.mode === "priceAndAmount" && active) {
2086
2084
  const pnl = amount();
2087
- return pnl === null ? priced : `${priced} ${formatMoney(pnl, symbol)}`;
2085
+ if (pnl !== null) return `${priced} ${formatMoney(pnl, symbol)}`;
2088
2086
  }
2089
- return `${typeLabel} ${price.toFixed(precision)}`;
2087
+ return priced;
2090
2088
  }
2091
2089
  var BRACKET_BASE_RATIO = 0.68;
2092
2090
  var BRACKET_COL_OFFSETS = [0, -0.08, 0.08];
@@ -21333,13 +21331,15 @@ var OrderLineTimeDragHandler = class _OrderLineTimeDragHandler {
21333
21331
  // src/core/priceReveal.ts
21334
21332
  var MIN_FACTOR = 0.1;
21335
21333
  var MAX_FACTOR = 10;
21336
- function revealPriceRange(displayed, prices, plotHeightPx, padPx = 24) {
21337
- const pts = prices.filter((p) => Number.isFinite(p));
21334
+ function revealPriceRange(displayed, prices, plotHeightPx, padPx = 24, maxSpan) {
21335
+ const pts = prices.filter((p) => Number.isFinite(p) && p > 0);
21338
21336
  const span = displayed.max - displayed.min;
21339
21337
  if (pts.length === 0 || !(span > 0) || !(plotHeightPx > 0)) return null;
21340
21338
  const lo = Math.min(...pts);
21341
21339
  const hi = Math.max(...pts);
21342
- if (lo >= displayed.min && hi <= displayed.max) return null;
21340
+ const needLo = lo < displayed.min;
21341
+ const needHi = hi > displayed.max;
21342
+ if (!needLo && !needHi) return null;
21343
21343
  let min = displayed.min;
21344
21344
  let max = displayed.max;
21345
21345
  for (let pass = 0; pass < 2; pass++) {
@@ -21347,6 +21347,20 @@ function revealPriceRange(displayed, prices, plotHeightPx, padPx = 24) {
21347
21347
  min = Math.min(displayed.min, lo - pad);
21348
21348
  max = Math.max(displayed.max, hi + pad);
21349
21349
  }
21350
+ if (maxSpan !== void 0 && max - min > maxSpan) {
21351
+ if (!(maxSpan > span)) return null;
21352
+ if (needLo && !needHi) {
21353
+ max = displayed.max;
21354
+ min = max - maxSpan;
21355
+ } else if (needHi && !needLo) {
21356
+ min = displayed.min;
21357
+ max = min + maxSpan;
21358
+ } else {
21359
+ const mid = (displayed.min + displayed.max) / 2;
21360
+ min = mid - maxSpan / 2;
21361
+ max = mid + maxSpan / 2;
21362
+ }
21363
+ }
21350
21364
  return { min, max };
21351
21365
  }
21352
21366
  function scaleAndPanFor(base, target) {
@@ -32321,7 +32335,8 @@ var _ChartEngine = class _ChartEngine {
32321
32335
  if (this.dataStore.length === 0 || this._lastInCompareMode) return;
32322
32336
  const { priceH } = this.getChartLayout();
32323
32337
  const displayed = this._displayedPriceRange ?? this.getScaledPriceRange(this.viewport);
32324
- const target = revealPriceRange(displayed, prices, priceH);
32338
+ const base = this._lockedAutoFitBase ?? displayed;
32339
+ const target = revealPriceRange(displayed, prices, priceH, 24, (base.max - base.min) * MAX_FACTOR);
32325
32340
  if (!target) return;
32326
32341
  if (this.scrollAnimId !== null) {
32327
32342
  cancelAnimationFrame(this.scrollAnimId);