calculate lot size

Created at 05 Jan 2025, 09:32
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!
RU

ruddymff

Joined 04.01.2025

calculate lot size
05 Jan 2025, 09:32


Hi

Following my recent post, the fromula to calculate my lot is :

LOT SIZE= RISK AMOUNT/DISTANCE STOP LOSS IN PIPS/PIP VALUE

Can any one help me to code this please?

This is my draft but there is return “BAD VOLUME”. I don't understand what is wrong

 double risk = ( riskAmount / stopLossDistance ) / 10;

            Print("Risk amount: {0}, Stop Loss Distance: {1}, Lot: {2}", riskAmount, stopLossDistance, risk);
            

             Print("Pip Value: {0}", Symbol.PipValue);

            // var lotSize = risk / Symbol.PipValue;

            // var lotSize = Math.Round(risk);

            //Print("Lot Size: {0}", Symbol.QuantityToVolumeInUnits(lotSize));

            return Symbol.QuantityToVolumeInUnits(risk);


@ruddymff