# TrailingStop

To protect your profits, you may want to have Dexible watch the market price of an asset and as long as it keeps going up in price, keep track of its peak price. No matter what, if it falls below a certain percentage of that peak price, you want to get out of the market as quickly as possible. This is what a trailing stop order will do. Dexible will keep a running record of the peak price and if it suddenly falls below your threshold, it will convert to a market order. Here is an example:

```
const ts = new TrailingStopSwap({
    amountIn:  units.inBNUnits("18000"),
    tokenIn: matic,
    tokenOut: usdc,
    slippage: new Slippage(.5, false),
    spotPercentage: 10,
});
```

In this example, it tells Dexible to keep watching the price of the MATIC-USDC market and if the price drops 10% off its peak at any time, exit the 18k MATIC position to USDC via a market order.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dexible.gitbook.io/dexible-sdk/major-sdk-components/algos/trailingstop.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
