Calculating Position Size (volume) works in USDJPY but the same calculation does not work in EURUSD correctly

Created at 08 Jan 2023, 05:33
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!
CT

ctid1779370

Joined 08.01.2023

Calculating Position Size (volume) works in USDJPY but the same calculation does not work in EURUSD correctly
08 Jan 2023, 05:33


Hi there,

I've written code inside my cBot that calculates my position size based on current entry point minus the stop loss position and risk allocated.

If I wish to risk $1,000 in USDJPY this gets my position size perfectly however the same math sizes my position far too small in EURUSD.

I seem to have found the value that requires changing to do this however I wish this calculation to work automatically for all pairs.

Anyone know what I am missing?

                // A Parameter entered in $value, eg risk $1000 type 1000
                var sell_risk_amount = RiskInUSD;
                // This is pulled from a variable above that calculates the stop loss distance in pips.
                var sell_stop_loss_pips = _SellStopLossPipPriceFinal;
                // Just the current ask price the used by getting var _previousAsk = Symbol.Ask;
                var sell_current_price = _previousAsk;

                // Lot size
                var sell_lot_size = Symbol.LotSize;
                
                // Some math 1 divided by the current price * lot size
                var sell_pip_value = (1 / sell_current_price) * sell_lot_size;

                // THIS IS THE ISSUE *********************************************************************
                // The value of 10000 at the end.
                // If i'm risking $1000 on USDJPY the calculation works perfectly.
                // However it sizes too small for EURUSD
                // If i change that value to 1000000 the sizing is then perfect for EURUSD but not USDJPY obviously.
                // How do i get this value to be automatic for every pair.
                var sell_position_size = (sell_risk_amount / sell_stop_loss_pips) / sell_pip_value * 10000; // This value determines the size. 10000 works for USDJPY  but 1000000 works for EURUSD for the same amount of risk? Why?
                var sell_final_position_size = Math.Round(sell_position_size, 0)*1000;


                // Then it will execute this order inside and if statement check
                ExecuteMarketRangeOrder(TradeType.Sell, SymbolName, sell_final_position_size, 2, Symbol.Ask, symbolLabel, _SellStopLossPipPriceFinal, TakeProfitInPips);

 


@ctid1779370
Replies

ctid2434759
08 Jan 2023, 09:08 ( Updated at: 09 Jan 2023, 06:50 )

Calculating Position Size (volume) works in USDJPY but the same calculation does not work in EURUSD correctly

Fixed it. Don't know how to delete the questions.


@ctid2434759