Issue with getting Volume amount right (US30)

Created at 18 Jul 2022, 11:04
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!
MA

marktbs

Joined 18.07.2022

Issue with getting Volume amount right (US30)
18 Jul 2022, 11:04


Hi

When I'm trying to get a volume for new position, out of risk percentage number, Im getting wrong values for US30

        protected override void OpenPosition()
        {
            // Initialize
            double RequestedPrice;
            TradeType TradeDirection;
            double OrderVolume;
            double RangeSize = 3;

            //// Open Position
            if (Trader.CurrentPosition == null)
            {

                if (TradeLogic(true, out buy))
                {
                    if (buy)
                    {
                        TradeDirection = TradeType.Buy;
                        RequestedPrice = Symbol.Bid;
                    }
                    else
                    {
                        TradeDirection = TradeType.Sell;
                        RequestedPrice = Symbol.Ask;
                    }

                    //// Volume calculation. Gives wrong numbers for base currencies other than account's currency + US30 wrong value
                    OrderVolume = (Account.Balance * Profile.TradingMargin_int / 100) * Account.PreciseLeverage; // Profile.TradingMargin_int = 20 (which is 20% of account balance)
                    OrderVolume = OrderVolume % 1000 >= 500 ? OrderVolume + 1000 - OrderVolume % 1000 : OrderVolume - OrderVolume % 1000; // Normalize volume

                    Trader.LatestOperation = ExecuteMarketRangeOrder(TradeDirection, Trader.symbol.Name, OrderVolume, RangeSize, RequestedPrice, "Label", Profile.StopLoss_double, Profile.TakeProfit_double); // Profile.StopLoss_double & Profile.TakeProfit_double = 6, 15
                    Trader.CurrentPosition = Trader.LatestOperation.Position;
                }

            }
        }

------------------

Account: 1'000 GBP (Profile.TradingMargin_int = 20, Leverage = 400)

Volume result for EURJPY / USDCHF: 80'000 (correct)

Volume result for XTIUSD: 20'000 (correct)

Volume result for US30: 40'000 (incorrect, should be 1?) <<


@marktbs
Replies

PanagiotisCharalampous
18 Jul 2022, 12:42

Hi marktbs,

This is because you need to convert the value you receive, which is in your account's currency, to the base asset value. 40000 is in GBP, you need to find out how many US 30 contracts you can buy for 40000 GBP.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous