Position.ModifyTakeProfit
method · Position · cAlgo.API Since 5.8
DesktopCLICloud
Shortcut for the Robot.ModifyPosition method to change the Take Profit protection
Overloads
| Signature |
|---|
ModifyTakeProfit(RelativeTakeProfitProtections takeProfitProtections) |
ModifyTakeProfit(AbsoluteTakeProfitProtections takeProfitProtections) |
ModifyTakeProfit(RelativeTakeProfitProtections takeProfitProtections)
Shortcut for the Robot.ModifyPosition method to change the Take Profit protection
TradeResult ModifyTakeProfit(RelativeTakeProfitProtections takeProfitProtections)
position.ModifyTakeProfit(takeProfitProtections: RelativeTakeProfitProtections) -> TradeResult
Parameters
| Name | C# type | Python type | Description |
|---|---|---|---|
takeProfitProtections | RelativeTakeProfitProtections | RelativeTakeProfitProtections | New Take Profit protections |
Returns TradeResult
Examples
var position = Positions.Find("myLabel");
if (position != null)
{
var halfVolume = position.Symbol.NormalizeVolumeInUnits(position.VolumeInUnits / 2, RoundingMode.Down);
var takeProfits = new RelativeTakeProfitProtections(new RelativeTakeProfitProtection(halfVolume, 20), new RelativeTakeProfitLastProtection(40));
var result = position.ModifyTakeProfit(takeProfits);
Print("Take profit ladder set: {0}", result.IsSuccessful);
}
position = api.Positions.Find("myLabel")
if position is not None:
halfVolume = position.Symbol.NormalizeVolumeInUnits(position.VolumeInUnits / 2, RoundingMode.Down)
takeProfits = RelativeTakeProfitProtections(RelativeTakeProfitProtection(halfVolume, 20), RelativeTakeProfitLastProtection(40))
result = position.ModifyTakeProfit(takeProfits)
api.Print(f"Take profit ladder set: {result.IsSuccessful}")
ModifyTakeProfit(AbsoluteTakeProfitProtections takeProfitProtections)
Shortcut for the Robot.ModifyPosition method to change the Take Profit protection
TradeResult ModifyTakeProfit(AbsoluteTakeProfitProtections takeProfitProtections)
position.ModifyTakeProfit(takeProfitProtections: AbsoluteTakeProfitProtections) -> TradeResult
Parameters
| Name | C# type | Python type | Description |
|---|---|---|---|
takeProfitProtections | AbsoluteTakeProfitProtections | AbsoluteTakeProfitProtections | New Take Profit protections |
Returns TradeResult
Examples
var position = Positions.Find("myLabel");
if (position != null)
{
var distance = 50 * position.Symbol.PipSize;
var targetPrice = position.TradeType == TradeType.Buy ? position.EntryPrice + distance : position.EntryPrice - distance;
var result = position.ModifyTakeProfit(new AbsoluteTakeProfitProtections(new AbsoluteTakeProfitLastProtection(targetPrice)));
Print("Take profit set at {0}: {1}", targetPrice, result.IsSuccessful);
}
position = api.Positions.Find("myLabel")
if position is not None:
distance = 50 * position.Symbol.PipSize
targetPrice = position.EntryPrice + distance if position.TradeType == TradeType.Buy else position.EntryPrice - distance
result = position.ModifyTakeProfit(AbsoluteTakeProfitProtections(AbsoluteTakeProfitLastProtection(targetPrice)))
api.Print(f"Take profit set at {targetPrice}: {result.IsSuccessful}")