SetProfitTarget()

Set a profit target to exit a trade in a profitable position.

This method can be used inside a strategy and which defines the difference in price of an asset which you bought in a particular trade. If the price increases 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 to collect profit.

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 profit target. If you use SetProfitTarget()more than once, the profit target 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, assume your strategy bought BTC and you want to close the position once the price rises by 5 USDT. You can do so by setting the profit target method as follows:

Basic example
Complete example
Basic example
// Close the position once the price rises by 5
SetProfitTarget(5);
Complete example
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);
}
});
}
}