SetStopLoss()

Set a stop loss to exit a trade if price decreases by specified amount.

This method can be used to define how much your strategy is willing to lose in one trade. Should the price decrease by a specified amount, your strategy will automatically close the position.

Parameters

Name

Type

Description

price

double

Here, price defines the difference in price between when the strategy opened the position and the price at which the strategy will close the position for a loss.

label

string

Optional parameter which can be used for labeling the signal generated by this method. Using labels can be useful in the process of developing and debugging your strategy.

Within the strategy, you can define only one stop loss. If you use SetStopLoss() more than once, the stop loss value will be overwritten by your latest settings.

The browser app doesn't show the custom labels in the UI at the moment. It will be updated in the future release.

Example

Lets suppose that your strategy is trading BTC/USDT and your strategy bought BTC. The risk which you are willing to take is a price decrease of 5 USDT, after which you want to close the position. To define this behavior, you would simply set the stoploss as follows:

// Close the position once the price decreases by 5
SetStopLoss(5);

Last updated