Auto lot size setting based on risk percentage

cTrader
2
Votes

ctid3066979 since: 22 Apr 2021;

  22 Apr 2021, 12:34
Auto lot size setting based on risk percentage

Not sure if my heading explain it enough but i will try go into detail. so basically would like feature that is available on mt4/5 position size calculator that we can have a fixed risk percentage and our lot size changes based on our entry and SL input. 

thanks

graham

ranjicgnr since: 22 Apr 2021;

  22 Apr 2021, 23:36
RE:

ctid3066979 said:

Not sure if my heading explain it enough but i will try go into detail. so basically would like feature that is available on mt4/5 position size calculator that we can have a fixed risk percentage and our lot size changes based on our entry and SL input. 

thanks

graham

Hai

You can use the below code for automating lot sizing on cAlgo. Also you can modify the way you wanted

                                     double longStopLoss = Math.Min(Bars.Last(1).Low, Bars.Last(2).Low) - (Symbol.PipValue * 0.5);
                                    double balance = Account.Balance;
                                    double riskAmount = balance * RiskPercent * 0.01;
                                    douuble longRiskPoints = Ask - longStopLoss;
                                    double volumeinLots = Math.Floor(((riskAmount / longRiskPoints) / Symbol.LotSize) * 100) / 100;
                                    double volumeInUnits = Symbol.QuantityToVolumeInUnits(volumeinLots);
                                    ExecuteMarketOrderAsync(TradeType.Buy, SymbolName, volumeInUnits, label);

I have used for EuroUSD. I have put last two bars low as stoploss.

ctid3066979 since: 22 Apr 2021;

  23 Apr 2021, 00:23

someone has replied but i cant seem to see it

louislamprell since: 23 Apr 2021;

  23 Apr 2021, 13:06
Absolutely agreed

I would like to be able to place my orders using a risk percentage settings instead of having to use a calc first and then change the lot size. I scalp so being able to quickly place an order at 1% of my bank means when prices quickly change and i need to adjust my order, I dont need to constantly recalculate the lots to ensure i am only risking 1%. The trade panel is fantastic on ctrader, for me the only thing missing is a percentage based risk setting

ranjicgnr since: 22 Apr 2021;

  27 Apr 2021, 13:57

I am coding one for risk based qty. You can suggest features. I will try to incorporate

ctid3066979 since: 22 Apr 2021;

  27 Apr 2021, 14:30
RE: RE:

ranjicgnr said:

ctid3066979 said:

Not sure if my heading explain it enough but i will try go into detail. so basically would like feature that is available on mt4/5 position size calculator that we can have a fixed risk percentage and our lot size changes based on our entry and SL input. 

thanks

graham

Hai

You can use the below code for automating lot sizing on cAlgo. Also you can modify the way you wanted

                                     double longStopLoss = Math.Min(Bars.Last(1).Low, Bars.Last(2).Low) - (Symbol.PipValue * 0.5);
                                    double balance = Account.Balance;
                                    double riskAmount = balance * RiskPercent * 0.01;
                                    douuble longRiskPoints = Ask - longStopLoss;
                                    double volumeinLots = Math.Floor(((riskAmount / longRiskPoints) / Symbol.LotSize) * 100) / 100;
                                    double volumeInUnits = Symbol.QuantityToVolumeInUnits(volumeinLots);
                                    ExecuteMarketOrderAsync(TradeType.Buy, SymbolName, volumeInUnits, label);

I have used for EuroUSD. I have put last two bars low as stoploss.

OK but do not have a clue what to do with that lol