get proper order size based on margin

Created at 26 Aug 2018, 12:49
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!
swingfish's avatar

swingfish

Joined 25.06.2016

get proper order size based on margin
26 Aug 2018, 12:49


i was to accomplish the following:

lets assume we have 10k USD free margin.

if a order is placed it should use a multitude of that margin for the position size.

in a Forex USD based pair thats easy to do but it gets alot more difficult if the asset is not forex and/or the account is in a different currency or the symbol does NOT start with USD

        [Parameter("Volume Multiplicator", DefaultValue = 8, MinValue = 0, Step = 1)]
        public double VMulti { get; set; }

i'm getting a multiplicator to set for the position size from settings 

 

                        double x = Account.FreeMargin * VMulti;
                        double z = Symbol.VolumeInUnitsToQuantity(x);

                        double _volume = Symbol.NormalizeVolumeInUnits(x, RoundingMode.Down);
                        ExecuteMarketOrder(signalLine.TradeType, Symbol, _volume, "auto entry", null, null);

that code however works ONLY on a forex pair starting with USD and calculates based on USD instead of the account currency.

is there a way to do this so it takes the cost of the asset in account in relation to the account currency ? 


@swingfish