Calculating volume correctly so that I am risking 1% of my account balance each time

Created at 11 Aug 2022, 21:56
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!
JA

jaydcrowe1989

Joined 11.08.2022

Calculating volume correctly so that I am risking 1% of my account balance each time
11 Aug 2022, 21:56


Hi,

 

I have my bot working now and I am confident it is placing the trades I want it to place during back testing. The problem I have is that I cannot seem to get it to calculate the correct volume.

 

I was wondering if someone could please help me and tell me how to calculate the volume correctly so that it can be used on any instrument and will only risk 1% of the account balance at the time it places the trade?

 

Regards,

Jay


@jaydcrowe1989
Replies

PanagiotisCharalampous
12 Aug 2022, 08:16

Hi there,

You can try something like this

                        var maxAmountRisked = Account.Equity * (RiskPercentage / 100);
                        return Symbol.NormalizeVolumeInUnits(maxAmountRisked / (StopLoss * Symbol.PipValue), RoundingMode.Down);

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

jaydcrowe1989
12 Aug 2022, 11:19

RE:

PanagiotisCharalampous said:

Hi there,

You can try something like this

                        var maxAmountRisked = Account.Equity * (RiskPercentage / 100);
                        return Symbol.NormalizeVolumeInUnits(maxAmountRisked / (StopLoss * Symbol.PipValue), RoundingMode.Down);

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Perfect. Thank you very much, I will give that a try.


@jaydcrowe1989

thecaffeinatedtrader
18 Aug 2022, 17:52 ( Updated at: 18 Aug 2022, 17:53 )

RE:

jaydcrowe1989 said:

Hi,

 

I have my bot working now and I am confident it is placing the trades I want it to place during back testing. The problem I have is that I cannot seem to get it to calculate the correct volume.

 

I was wondering if someone could please help me and tell me how to calculate the volume correctly so that it can be used on any instrument and will only risk 1% of the account balance at the time it places the trade?

 

Regards,

Jay

 

I have been using this successfully, enjoy

[Parameter("Risk %", DefaultValue = 1.00, MinValue = 0.01, MaxValue = 5.00, Step = 0.01, Group = "Risk Management")]
public double RiskPerTrade { get; set; }

	{
	ExecuteMarketOrder(TradeType.Buy, SymbolName, GetVolume(StopLoss), InstanceName, StopLoss, TakeProfit);
	}

	{
	ExecuteMarketOrder(TradeType.Sell, SymbolName, GetVolume(StopLoss), InstanceName, StopLoss, TakeProfit);
	}

private double GetVolume(double? stopLossPips = null)
	{
	double costPerPip = (double)((int)(Symbol.PipValue * 10000000)) / 100;

	// Change this to Account.Equity if you want to
	double baseNumber = Account.Balance;

	double sizeInLots = Math.Round((baseNumber * RiskPerTrade / 100) / (stopLossPips.Value * costPerPip), 1);

	var result = Symbol.QuantityToVolumeInUnits(sizeInLots);

	return result;
	}

 


@thecaffeinatedtrader