Function slPriceToPercentShift

Convert an absolute stop-loss price to a percentShift for commitTrailingStop.

percentShift = newSlDistancePercent - originalSlDistancePercent where distance = Math.abs((effectivePriceOpen - slPrice) / effectivePriceOpen * 100)

// LONG: entry=100, originalSL=90, desired newSL=95
const shift = slPriceToPercentShift(95, 90, 100); // -5
await commitTrailingStop("BTCUSDT", shift, currentPrice);
  • Parameters

    • newStopLossPrice: number

      Desired absolute stop-loss price

    • originalStopLossPrice: number

      Original stop-loss price from the pending signal

    • effectivePriceOpen: number

      Effective entry price (from getPositionEffectivePrice)

    Returns number

    percentShift to pass to commitTrailingStop