Executing order with volume based on balance

Created at 04 Sep 2015, 02: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!
whis.gg's avatar

whis.gg

Joined 31.08.2015

Executing order with volume based on balance
04 Sep 2015, 02:32


Hello again,

is there way to make cBot execute an order with let's say 1% of balance as volume?

Thanks in advance.


@whis.gg
Replies

Spotware
04 Sep 2015, 03:14

Dear Trader,

You just need to retrieve your account balance and then normalize the volume (divided to 100 for percentage) to be able to open a position with a valid volume. The following code snippet illustrates it:

            double balance = Account.Balance;

            long volume = Symbol.NormalizeVolume(balance / 100, RoundingMode.Down);

            ExecuteMarketOrder(TradeType.Buy, Symbol, volume);

Additionally we recommend you to take a look at our API reference.


@Spotware