Function tpPriceToPercentShift

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

percentShift = newTpDistancePercent - originalTpDistancePercent where distance = Math.abs((tpPrice - effectivePriceOpen) / effectivePriceOpen * 100)

// LONG: entry=100, originalTP=110, desired newTP=107
const shift = tpPriceToPercentShift(107, 110, 100); // -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)

    Returns number

    percentShift to pass to commitTrailingTake