Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Forum on trading, automated trading systems and testing trading strategies
calculating volume based on risk amount for gold
Fernando Carreiro, 2023.12.10 21:05
In MQL5, you can just use the function OrderCalcProfit instead.Forum on trading, automated trading systems and testing trading strategies
Trying to replicate OrderCalcMargin()
Fernando Carreiro, 2023.10.31 22:40
You will find it here ... https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants#enum_symbol_calc_mode
Both the OrderCalcMargin and OrderCalcProfit functions will calculate differently depending on the ENUM_SYMBOL_CALC_MODE
Forum on trading, automated trading systems and testing trading strategies
SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE) sometimes zero
Fernando Carreiro, 2022.08.23 17:41
You can! These are the steps I take. I supply the function with a lot size equal to the “Max Lot Size” allowed for the symbol in question, then calculate the ratio needed to achieve the fractional risk that I wish to apply, to get the correct volume for the order. I then align that with the “Lot Step” and finally check it against both the maximum and minimum allowed lots for the symbol.
The reason I use the “maximum” lots instead of just “1.0” lots as a reference value is because there is no guarantee that the value of 1.0 is within the minimum and maximum values allowed. Given that using 1.0, or the maximum, gives equivalent results anyway (by using the ratio method), I choose to use the “max lots” as the reference point which also offers the most precision for the calculation.
Something like this ...
// This code will not compile. It is only a example reference if( OrderCalcProfit( eOrderType, _Symbol, dbLotsMax, dbPriceOpen, dbPriceStopLoss, dbProfit ) ) { dbOrderLots = fmin( fmax( round( dbRiskMax * dbLotsMax / ( -dbProfit * dbLotsStep ) ) * dbLotsStep, dbLotsMin ), dbLotsMax ); // the rest of the code ... };

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Calculating a Risk Percentage before opening a new trade is popular in the public domain, but getting a percentage of balance used after the trade has been opened seems difficult for me to calculate.
Here's what I came up with, but got something around 3.7k(3,700+).
Has anyone ever tried to calculate risk percentage of a closed trade before or can help set my head at the right edge?
I'm thankful in advance.