Function partialLoss

  • Executes partial close at loss level (moving toward SL).

    Closes a percentage of the active pending position at loss. Price must be moving toward stop loss (in loss direction).

    Automatically detects backtest/live mode from execution context.

    Parameters

    • symbol: string

      Trading pair symbol

    • percentToClose: number

      Percentage of position to close (0-100, absolute value)

    Returns Promise<boolean>

    Promise - true if partial close executed, false if skipped

    Error if currentPrice is not in loss direction:

    • LONG: currentPrice must be < priceOpen
    • SHORT: currentPrice must be > priceOpen
    import { partialLoss } from "backtest-kit";

    // Close 40% of LONG position at loss
    const success = await partialLoss("BTCUSDT", 40);
    if (success) {
    console.log('Partial loss executed');
    }