Convert an absolute stop-loss price to a percentShift for commitTrailingStop.
commitTrailingStop
percentShift = newSlDistancePercent - originalSlDistancePercent where distance = Math.abs((effectivePriceOpen - slPrice) / effectivePriceOpen * 100)
// LONG: entry=100, originalSL=90, desired newSL=95const shift = slPriceToPercentShift(95, 90, 100); // -5await commitTrailingStop("BTCUSDT", shift, currentPrice); Copy
// LONG: entry=100, originalSL=90, desired newSL=95const shift = slPriceToPercentShift(95, 90, 100); // -5await commitTrailingStop("BTCUSDT", shift, currentPrice);
Desired absolute stop-loss price
Original stop-loss price from the pending signal
Effective entry price (from getPositionEffectivePrice)
getPositionEffectivePrice
percentShift to pass to commitTrailingStop
Convert an absolute stop-loss price to a percentShift for
commitTrailingStop.percentShift = newSlDistancePercent - originalSlDistancePercent where distance = Math.abs((effectivePriceOpen - slPrice) / effectivePriceOpen * 100)
Example