inserting commission in risk calculation

Created at 04 Aug 2021, 09:17
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!
YA

yaghouti

Joined 19.12.2019

inserting commission in risk calculation
04 Aug 2021, 09:17


Hi

i use this code for calculating the volume per risk:

/// <summary>
/// Returns the amount of volume based on your provided risk percentage and stop loss
/// </summary>
/// <param name="symbol">The symbol</param>
/// <param name="riskPercentage">Risk percentage amount</param>
/// <param name="accountBalance">The account balance</param>
/// <param name="stopLossInPips">Stop loss amount in Pips</param>
/// <returns>double</returns>
public static double GetVolume(this Symbol symbol, double riskPercentage, double accountBalance, double stopLossInPips)
{
return symbol.NormalizeVolumeInUnits(riskPercentage / (Math.Abs(stopLossInPips) * symbol.PipValue / accountBalance * 100));
}

how is it possible to consider symbol commission inside this?

after opening position we can get the commission with position.Commissions but before entering the position how could we get it to insert this formula?

 

the second point is above code do not consider spread, how could we consider spread in this volume calculation?


@yaghouti
Replies

PanagiotisCharalampous
04 Aug 2021, 10:12

Hi yaghouti,

At the moment commission information is not available in cTrader Automate API. Spread is not really relevant to this calculation since it is embedded in the actual price.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 


@PanagiotisCharalampous

firemyst
22 Sep 2021, 04:38

RE:

PanagiotisCharalampous said:

Hi yaghouti,

At the moment commission information is not available in cTrader Automate API. Spread is not really relevant to this calculation since it is embedded in the actual price.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 

 

What about this? Although you can only obtain it _after_ a position is opened:


@firemyst