How to code Increase of lot size

Created at 15 Nov 2024, 16:03
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
GA

GauchoHood

Joined 20.08.2024

How to code Increase of lot size
15 Nov 2024, 16:03


Hi, I am trying to generate a script that increases the lotsize, of my original position as the position grows positive. 

For example, after a 40 pips profit double the Lotsize. When talking to chatgpt, it said, ctrader does not allow to modify the lotsize directly, and I would need to open a new positio. I stead. Although, Ctrader has a “double lot size” button itself, so I assume there is a method or api that could do it. Please help! Thank you.for.reading!


@GauchoHood
Replies

PanagiotisCharalampous
16 Nov 2024, 11:45

Hi there,

You can use the ModifyPosition method to change your position's volume.

Best regards,

Panagiotis


@PanagiotisCharalampous

GauchoHood
16 Nov 2024, 14:10 ( Updated at: 16 Nov 2024, 18:59 )

RE: How to code Increase of lot size
PanagiotisCharalampous said:

Hi there,

You can use the ModifyPosition method to change your position's volume.

Best regards,

Panagiotis


@GauchoHood

GauchoHood
16 Nov 2024, 14:39 ( Updated at: 16 Nov 2024, 18:59 )

RE: RE: How to code Increase of lot size

GauchoHood said: 

PanagiotisCharalampous said: 

Hi there,

You can use the ModifyPosition method to change your position's volume.

Best regards,

Panagiotis

 

Hi Panagiotis. if (position.UnrealizedNetProfit >= profitThreshold)
{
   // Tried to adjust the volume
   double newVolume = position.VolumeInUnits * multiplier;
   position.ModifyPosition(newVolume); // Attempted this, but it did not work
}

attempted to use the ModifyPosition method to adjust the position's volume based on certain profit thresholds. Here’s the code I used:.

However, this did not work. Upon further reading, I discovered that ModifyPosition is designed to modify properties like stop loss and take profit, and not the position's volume.

Could you confirm if there’s a method or approach to modify the volume of an open position directly, or if this is strictly not supported in cTrader?


@GauchoHood