Signals Help Center
  • About Signals
  • Getting Started
    • Tutorials
      • Your First Strategy
        • Create a New Strategy
        • Define Variables
        • Define Setup Method
        • Define Register Actions Method
        • Backtest
        • Deploy Strategy & Start Receiving Signals
    • Dashboard
    • Strategies
      • Strategy Tools and Settings
        • Editor
        • Strategy Detail
        • Backtests
          • Backtest Detail
          • Deploying a Backtest
          • Delete a Backtest
        • Deployments
          • Deployment Detail
          • Edit About, Rules & Alternative Markets
          • Undeploy an Active Deployment
          • (Un)Publish a Deployment
          • (Un)Follow a Deployment
          • Delete a Deployment
        • Followings
          • Following Detail
          • Unfollow a Deployment
          • Delete Record of Following
      • Strategies Marketplace
        • Follow a Strategy
        • Publish Strategy
      • Strategy Details
      • Strategy Metrics
        • Initial Capital
        • Initial Capital (USDT)
        • Strategy Balance
        • Strategy Balance (USDT)
        • Total Performance
        • Total Performance (USDT)
      • Strategy Types
        • Single Market Strategy
        • Multi Market Strategy
    • Account
      • Change Plan
      • Change or Reset Password
      • Change Name, Username, or E-mail
  • Framework Documentation
    • Strategy
      • Methods
        • Setup()
          • DataMarketplace
          • IndicatorsMarketplace
        • RegisterActions()
        • Orders Management
          • CancelOrder()
          • CancelAllPendingOrders()
          • EnterLong()
          • EnterLongLimit()
          • EnterShort()
          • EnterLongStop()
          • EnterShortLimit()
          • ExitLong()
          • EnterShortStop()
          • ExitLongLimit()
          • ExitShort()
          • ExitShortLimit()
          • ExitLongStop()
          • ExitShortStop()
        • Risk Management
          • SetProfitTarget()
          • SetStopLoss()
      • Properties
        • Market
        • Markets
        • PendingOrders
        • Position
        • Time
      • Types
        • IOrder
        • PendingOrder
    • Data
    • Logs
  • Knowledge Base
    • Vocabulary
      • Base currency
      • Deployment
      • Following
      • Quote currency
      • Strategy
    • Technical Indicators
      • Oscillators
        • Average Directional Index (ADX)
        • Momentum Indicator (MOM)
        • Moving Average Convergence Divergence (MACD)
        • Relative Strength Index (RSI)
        • Stochastic RSI (STOCH RSI)
      • Volatility
        • Average True Range (ATR)
        • Bollinger Bands (BB)
      • Trend Analysis
        • Exponential Moving Average (EMA)
        • Simple Moving Average (SMA)
        • Volume-weighted Moving Average (VWMA)
        • Weighted Moving Average (WMA)
      • Volume
        • Accumulation/Distribution Line (ADL)
  • Have a question?
    • FAQ
    • Ask on the forums
    • Contact us
Powered by GitBook
On this page
  1. Framework Documentation
  2. Strategy
  3. Methods
  4. Risk Management

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);
using Signals.DataSeries.Bars;
using Signals.Framework;
using Signals.Indicators.Bollinger;
using Signals.Indicators.ATR;

public class BollingerBands : SingleMarketStrategy
{
    private Bars twoHoursBars;
    private Bars minuteBars;

    private Bollinger bb;
    private ATR atr;
    
    private double entryPrice;
    private double breakEven = double.MaxValue;

    private const double multiplier1 = 5;
    private const double multiplier2 = 3;
    private const double multiplier3 = 3;

    public override void Setup(DataMarketplace data, IndicatorsMarketplace indicators)
    {
        twoHoursBars = data.Bars(BarPeriodType.Hour, 2).WithOffset(25);
        minuteBars = data.Bars(BarPeriodType.Minute, 1).WithOffset(25);

        bb = indicators.Bollinger(2.0, 20).Keep(2).OnSeries(twoHoursBars.Close);
        atr = indicators.ATR(14).OnSeries(twoHoursBars);
    }

    public override void RegisterActions()
    {
        OnUpdateOf(twoHoursBars).Do(() =>
        {
            if (!Position.InPosition)
            {
                CancelAllPendingOrders();

                var atrValue = atr.Value;
                entryPrice = bb.Value.Upper;
                breakEven = entryPrice + atrValue * multiplier3;
                
                EnterLongStop(entryPrice);

                SetProfitTarget(atrValue * multiplier1);
                SetStopLoss(atrValue * multiplier2);
            }
        });

        OnUpdateOf(minuteBars).Do(() =>
        {
            if ((Position.InPosition) && (minuteBars.High[0] > breakEven))
            {
                SetStopLoss(0);
            }
        });
    }
}

PreviousSetProfitTarget()NextProperties

Last updated 5 years ago