Calculating volume correctly so that I am risking 1% of my account balance each time
 
    
            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
Replies
                     Affluent_Trading
                     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
Perfect. Thank you very much, I will give that a try.
@Affluent_Trading
                     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

PanagiotisCharalampous
12 Aug 2022, 08:16
Hi there,
You can try something like this
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous