Function tpPriceToPercentShift

Convert an absolute take-profit price to a percentShift for commitTrailingTake.

percentShift = newTpDistancePercent - originalTpDistancePercent

The new distance is SIGNED by position direction (mirrors how ClientStrategy applies the shift): a take-profit moved past the entry produces a negative distance, so any target price is expressible — tpPercentShiftToPrice(tpPriceToPercentShift(x, ...), ...) === x holds for targets on both sides of the entry.

LONG: newTpDistancePercent = (newTakeProfitPrice - effectivePriceOpen) / effectivePriceOpen * 100 SHORT: newTpDistancePercent = (effectivePriceOpen - newTakeProfitPrice) / effectivePriceOpen * 100

// LONG: entry=100, originalTP=110, desired newTP=107
const shift = tpPriceToPercentShift(107, 110, 100, "long"); // -3
await commitTrailingTake("BTCUSDT", shift, currentPrice);
  • Parameters

    • newTakeProfitPrice: number

      Desired absolute take-profit price

    • originalTakeProfitPrice: number

      Original take-profit price from the pending signal

    • effectivePriceOpen: number

      Effective entry price (from getPositionEffectivePrice)

    • position: "long" | "short"

      Position direction: "long" or "short"

    Returns number

    percentShift to pass to commitTrailingTake