Function slPercentShiftToPrice

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

Inverse of slPriceToPercentShift.

newSlDistancePercent = originalSlDistancePercent + percentShift LONG: newStopLossPrice = effectivePriceOpen * (1 - newSlDistancePercent / 100) SHORT: newStopLossPrice = effectivePriceOpen * (1 + newSlDistancePercent / 100)

// LONG: entry=100, originalSL=90, percentShift=-5
const price = slPercentShiftToPrice(-5, 90, 100, "long"); // 95
  • Parameters

    • percentShift: number

      Value returned by slPriceToPercentShift (or passed to commitTrailingStop)

    • originalStopLossPrice: number

      Original stop-loss price from the pending signal

    • effectivePriceOpen: number

      Effective entry price (from getPositionEffectivePrice)

    • position: "long" | "short"

      Position direction: "long" or "short"

    Returns number

    Absolute stop-loss price corresponding to the given percentShift